iOS开发(3)UIButton
? ? UIButton就是按鈕 ?很簡單 ?只有一個樣式的創建和點擊觸發時間
創建uibutton主要有兩種方式
第一種是蘋果自帶的風格
UIButton *bu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ?蘋果提供了以下幾種uibuttontype
UIButtonTypeCustom自定義,可以通過給button設置title來做一個文字按鈕
UIButtonTypeSystem標準樣式UIButtonTypeDetailDisclosure 向右的箭頭
UIButtonTypeInfoDark這種i字按鈕
UIButtonTypeContactAdd添加樣式
UIButtonTypeRoundedRect經典的樣式,喬布斯時代的立體感,ios7已經被扁平化。
//給按鍵寫上文字
? ? [self.myButten setTitle:@"確認" forState:UIControlStateNormal];
? ? [self.myButten setTitle:@"取消" forState:UIControlStateHighlighted];
?? ?
? ? //設置文字字體
? ? self.myButten.titleLabel.font = [UIFont fontWithName:@"Arial" size:25];
?? ?
? ? //設置文字顏色
? ? self.myButten.titleLabel.textColor = [UIColor purpleColor];
第二種是把圖片做成按鈕
[self.myButten setImage:image forState:UIControlStateNormal]
forstate參數表示按鈕的狀態 ?常用的就兩種UIControlStateNormal正常,
UIControlStateHighlighted高亮
//給按鈕添加方法
[self.myButten addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
ControlEvents指的是按鈕出發的方式,這里UIControlEventTouchUpInside就是最常見的點擊
然后可以在click方法里面可以讓按鈕點擊之后的操作
- (void)click:(UIButton *)bu1
{
? ? NSLog(@"你點到我了");
}
總結
以上是生活随笔為你收集整理的iOS开发(3)UIButton的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS开发(2)UILabel学习
- 下一篇: UITableView的beginUpd