1
我想向UISegmentedControl添加一個小的彩色指示器(只是一個彩色的矩形)。我以爲我可以繼承UISegmentedControl並添加標誌initWithFrame這樣的:繼承UISegmentedControl以在每個片段上添加一個彩色的UIView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIColor *first = [UIColor blueColor];
UIColor *second = [UIColor orangeColor];
UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(self.bounds.origin.x + 5, self.bounds.origin.y + 5, 10, self.bounds.size.height)];
firstView.backgroundColor = first;
[self addSubview:firstView];
}
return self;
}
當我實例化一個對象CustomSegmentedControl,我剛剛得到的藍色長方形,但沒有其他的原畫segmentedcontrol邏輯。有什麼想法嗎?謝謝。
可以爲彩色矩形設置圖像。我有同樣的問題,但我試圖擺脫使用整套.pngs。我也要繼承子類。 – piperchester