2011年2月23日 星期三

UITabBar更改背景色彩方法

今天在做介面設計時,
突然之間想利用UITabBar,
不過UITabBar本身背景色係黑色,
太單調了,所以想到要清空它的背景色,
於是在網上找到思路,實現了

其實原理很簡單,哪個黑色背景原來是在UIView的drawRect:畫上去的,
因此我利用了Objective-c的method特性就完成了我的目的

@implementation UITabBar (CustomBackgound)
- (void)drawRect:(CGRect)rect {
}
@end

之後alloc UITabBar時設定它的背景色為clear color即可。

PS.1:其實你還可以利用subclass去達到相同效果
PS.2:這個方法不止可以清空背景,還可以利用圖片去作UITabBar的背景

UISlider不見了軌道的方法

@interface UINoBgSlider : UISlider
{
}

@end

@implementation UINoBgSlider

// implementation this method to not draw the slider track
- (CGRect)trackRectForBounds:(CGRect)bounds
{
return CGRectZero;
}

// implementation this method to handle the slider thumb control position
- (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
{
return CGRectMake(x, y, width, height);
}

@end

2011年2月16日 星期三

令iPhone SDK代碼分辨是「模擬器」還是「真機」

在開發 iPhone 軟件的過程中,有時會用到一些功能是無法在模擬器內運作。
可以用以下方法去使用SDK代碼分辨是「模擬器」還是「真機」

#if (TARGET_IPHONE_SIMULATOR)
// Simulator
#endif

#if !(TARGET_IPHONE_SIMULATOR)
// Real device
#endif

轉貼至:Pacess Laboratory

iPhone SDK-使用NSTimerInterval計算時差

今日用到NSTimerInterval去計算時間,
NSTimerInterval本身是以秒為單為,
所以兩個NSTimerInterval相減就可以得到時間差

NSTimerInterval轉為分鐘:
minutes = floor(NSTimerInterval/60);

NSTimerInterval轉為小時:
minutes = floor(NSTimerInterval/3600);