2013-03-21 70 views
-1

我是iphone開發的noob,我嘗試實現玻璃按鈕時有一個奇怪的問題(found here)。我的構建失敗了,因爲我在MOGlassButtons.m文件中出現了「程序錯誤中意外的@」。我一直無法找到有關如何解決此問題的任何信息。任何幫助是極大的讚賞。問題實現玻璃按鈕UIButton

MOGlassButton.m

self.gradientLayer1.colors = @[(id)[MO_RGBACOLOR(255, 255, 255, 0.45) CGColor], (id)[MO_RGBACOLOR(255, 235, 255, 0.1) CGColor]]; //<--"unexpected @ in program error" 

self.gradientLayer2.colors = @[(id)[MO_RGBACOLOR(205, 205, 205, 0) CGColor], (id)[MO_RGBACOLOR(235, 215, 215, 0.2) CGColor]]; //<--"unexpected @ in program error" 

編輯

#import "MOGlassButton.h" 

// Courtesy of https://github.com/facebook/three20 
#ifndef MO_RGBCOLOR 
#define MO_RGBCOLOR(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1] 
#endif 
#ifndef MO_RGBCOLOR1 
#define MO_RGBCOLOR1(c) [UIColor colorWithRed:c/255.0 green:c/255.0 blue:c/255.0 alpha:1] 
#endif 
#ifndef MO_RGBACOLOR 
#define MO_RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a] 
#endif 
+0

您能向我們展示MO_RGBACOLOR嗎?如果它,如我所料,宏觀,它可能是罪魁禍首。 – 2013-03-21 23:23:18

+0

@JuliusMaximilianSteen請檢查我的編輯 – 2013-03-21 23:26:43

+0

你不能只是將CGColorRef轉換爲ID,爲什麼你不只是存儲UIColor – 2013-03-21 23:53:05

回答

1

你的問題很可能是Xcode中的過時的版本,正在運行。您的代碼使用自Xcode 4.4以來支持的Objective-C文字(@[…]部分),因此在早期版本中無效。 (請參閱What are the details of "Objective-C Literals" mentioned in the Xcode 4.4 release notes?

升級應解決您的問題。

編輯

另外,雖然我嚴重推薦更新,您可以使用以下。

[NSArray arrayWithObjects: (id)[MO_RGBACOLOR(255, 255, 255, 0.45) CGColor], (id)[MO_RGBACOLOR(255, 235, 255, 0.1) CGColor], nil];