- Button類型
typedef enum {
UIButtonTypeCustom = 0,
UIButtonTypeRoundedRect,
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
} UIButtonType; - 注意採用 buttonWithType 的情況,
- 宣告時有 alloc 的話,需要手動relase,例如
button = [[UIButton alloc] init];
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom]retain]; - Selected 需要自行更改
- 設定圖片
[button setBackgroundImage:someImage forState:UIControlStateSelected];
self.checkInButton.selected = YES; - 基本用法
UIButton *mouse = [UIButton buttonWithType:UIButtonTypeCustom];
[mouse setFrame:CGRectMake(90.0f, 55.0f, 118.0f, 118.0f)];
[mouse setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[mouse setTitle:@"Mouse" forState:UIControlStateNormal];
[mouse.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:20]];
[mouse setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[mouse addTarget: self action: @selector(mouseClick:) forControlEvents: UIControlEventTouchDown];
[parent addSubview:mouse]; - 漸層UIButton需要以UIButton 擴展的第三方元件,或由美工直接做出底圖。
參考 Custom UIButton without using any images - Radio Buttons,
- 參考 iPhone UIButton tutorial: Radio Buttons
- 直接改圖
Radio ON http://findicons.com/icon/118309/ui_radio_button?id=122817
Radio OFF http://findicons.com/icon/118712/ui_radio_button_uncheck?id=118712
- 使用 UISegmentedControl - CustomBadge
參考 CustomBadge 或 Three320/TTButton 也有範例。
問題
可以用 UISegmentedControl 做出漸層的按鈕,但不知如何 binding 事件
http://charles.lescampeurs.org/2011/02/10/tint-color-uibutton-and-uibarbuttonitem
以前月曆上的美夢,現在實現了
2 週前