高度自定義的 iOS 單選按鈕:DLRadioButton

jopen 10年前發布 | 65K 次閱讀 iOS開發 移動開發 DLRadioButton

DLRadioButton 是高度自定義的 iOS 單選按鈕。

高度自定義的 iOS 單選按鈕:DLRadioButtonscreenshot2

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

To use this Pod from interface builder:

  • Put some UIButtons onto a View
  • Change the UIButtons' type to "custom"

change UIButton Type

  • Set the UIButtons' class to "DLRadioButton"

change UIButton Class

  • Set "otherButtons" outlet

set otherButtons outlet

To use this Pod from code:

#import "DLRadioButton.h"

// programmatically add buttons

// first button
DLRadioButton *firstRadioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(30, 200, 200, 30)];
firstRadioButton.buttonSideLength = 30;
[firstRadioButton setTitle:@"Red Button" forState:UIControlStateNormal];
[firstRadioButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
firstRadioButton.circleColor = [UIColor redColor];
firstRadioButton.indicatorColor = [UIColor redColor];
firstRadioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

// add other buttons
[self.view addSubview:firstRadioButton];
NSArray *colorNames = @[@"Orange", @"Green", @"Cyon", @"Blue", @"Purple"];
NSArray *buttonColors = @[[UIColor orangeColor], [UIColor greenColor], [UIColor cyanColor], [UIColor blueColor], [UIColor purpleColor]];
NSInteger i = 0;
NSMutableArray *otherButtons = [NSMutableArray new];
for (UIColor *buttonColor in buttonColors) {
    // customize this button
    DLRadioButton *radioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(30, 240+40*i, 200, 30)];
    radioButton.buttonSideLength = 30;
    [radioButton setTitle:[colorNames[i] stringByAppendingString:@" Button"] forState:UIControlStateNormal];
    [radioButton setTitleColor:buttonColor forState:UIControlStateNormal];
    radioButton.circleColor = buttonColor;
    radioButton.indicatorColor = buttonColor;
    radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [otherButtons addObject:radioButton];
    [self.view addSubview:radioButton];
    i++;
}
firstRadioButton.otherButtons = otherButtons;

To customize DLRadiobutton:

There are a bunch of properties that you can set for your Radio Button, please use the following picture for reference:DLRadioButton

項目主頁:http://www.baiduhome.net/lib/view/home/1414134180778

 

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!