2012-04-30 11 views
1

UISegmentedControlに少し色付いたインジケータ(単色の矩形)を追加します。私はUISegmentedControlをサブクラス化し、このようにinitWithFrameでそのフラグを追加すると考えていた:私はCustomSegmentedControlオブジェクトをインスタンス化するとき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; 
} 

が、私はちょうど青い四角形を取得しますが、他の元segmentedcontrol描画ロジックのどれも。何かご意見は?ありがとう。

答えて

1

クリスタル、

色の付いた四角形の画像を使用できますか?その場合は、

- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment 

を追加することができます。何かのように

[segmentedControl setImage:[UIImage imageNamed:@"blueRectangle"] forSegmentAtIndex:0]; 

希望します。

+0

色付き矩形の画像を設定することができます。私は同じ問題がありますが、私は全体のセット.pngsを使用することから離れようとしています。私もサブクラス化しようとしています。 – piperchester

関連する問題