鍍金池/ 教程/ iOS/ iOS - Buttons(按鈕)
iOS - Switches(切換/開關(guān))
iOS - Labels(標簽)
iOS - Table View(表格視圖)
IOS - 攝像頭管理
iOS - Text View(文本視圖)
IOS - 開發(fā)環(huán)境配置
iOS教程
iOS - Twitter & Facebook
iOS - UI元素
iOS - iAd 整合
IOS - 應用程序調(diào)試
iOS - Split View(分割視圖)
iOS - Status Bar(狀態(tài)欄)
iOS - Navigation Bar(導航欄)
iOS - Tab bar(標簽欄)
IOS - 文件處理
IOS - 自動布局
iOS - Image View(圖像視圖)
iOS - 應用程序內(nèi)購買
iOS - Pickers(選取器)
iOS - Delegates實例
iOS - 創(chuàng)建第一個iPhone應用
iOS (iPhone, iPad)教程
iOS - 發(fā)送電子郵箱(Email)
iOS - View Transitions(視圖轉(zhuǎn)換)
iOS - 內(nèi)存管理
iOS - Icons(圖標)
iOS - 音頻和視頻
iOS - Storyboards(演示圖板演)
iOS - Buttons(按鈕)
iOS - Text Field(文本域)
iOS - Sliders(滑動條)
iOS - Scroll View(滾動視圖)
IOS - 輸入類型 文本字段
iOS - 位置處理
iOS - Accelerometer(加速度傳感器)
IOS - 快速入門
iOS - SQLite 數(shù)據(jù)庫
iOS - GameKit
IOS - 訪問地圖
iOS - Objective-C基礎(chǔ)
iOS - Toolbar(工具欄)
IOS - 動作和插座(Outlets)
iOS - Alerts(警示)
IOS - 通用應用程序

iOS - Buttons(按鈕)

按鈕的使用

IOS中 Button(按鈕)是用來處理用戶的操作。它截取的觸摸事件,并發(fā)送消息到目標對象。

圓矩形按鈕

iOS Tutorial

XIB中的按鈕屬性

實用程序區(qū)(右側(cè)窗口),在屬性檢查器中,可以在 xib 改變按鈕的屬性。

iOS Tutorial

 

按鈕類型

  • UIButtonTypeCustom

  • UIButtonTypeRoundedRect

  • UIButtonTypeDetailDisclosure

  • UIButtonTypeInfoLight

  • UIButtonTypeInfoDark

  • UIButtonTypeContactAdd

重要的屬性

  • imageView

  • titleLabel

重要的方法

+ (id)buttonWithType:(UIButtonType)buttonType
- (UIImage *)backgroundImageForState:(UIControlState)state
- (UIImage *)imageForState:(UIControlState)state
- (void)setTitle:(NSString *)title forState:(UIControlState)state
- (void)addTarget:(id)target action:(SEL)action forControlEvents: (UIControlEvents) controlEvents

 

添加一個自定義的方法addDifferentTypesOfButton

-(void)addDifferentTypesOfButton
{
    // A rounded Rect button created by using class method
    UIButton *roundRectButton = [UIButton buttonWithType:
    UIButtonTypeRoundedRect];
    [roundRectButton setFrame:CGRectMake(60, 50, 200, 40)];
    // sets title for the button
    [roundRectButton setTitle:@"Rounded Rect Button" forState:
    UIControlStateNormal];
    [self.view addSubview:roundRectButton];
    
    UIButton *customButton = [UIButton buttonWithType: UIButtonTypeCustom];
    [customButton setBackgroundColor: [UIColor lightGrayColor]];
    [customButton setTitleColor:[UIColor blackColor] forState:
    UIControlStateHighlighted];
    //sets background image for normal state	
    [customButton setBackgroundImage:[UIImage imageNamed:
    @"Button_Default.png"] 
    forState:UIControlStateNormal];
    //sets background image for highlighted state
    [customButton setBackgroundImage:[UIImage imageNamed: 
    @"Button_Highlighted.png"] 
    forState:UIControlStateHighlighted];
    [customButton setFrame:CGRectMake(60, 100, 200, 40)];
    [customButton setTitle:@"Custom Button" forState:UIControlStateNormal];
    [self.view addSubview:customButton];
    
    UIButton *detailDisclosureButton = [UIButton buttonWithType:
    UIButtonTypeDetailDisclosure];
    [detailDisclosureButton setFrame:CGRectMake(60, 150, 200, 40)];
    [detailDisclosureButton setTitle:@"Detail disclosure" forState:
    UIControlStateNormal];
    [self.view addSubview:detailDisclosureButton];
    
    UIButton *contactButton = [UIButton buttonWithType:
    UIButtonTypeContactAdd];
    [contactButton setFrame:CGRectMake(60, 200, 200, 40)];
    [self.view addSubview:contactButton];
    
    UIButton *infoDarkButton = [UIButton buttonWithType:
    上一篇:iOS - Status Bar(狀態(tài)欄)下一篇:IOS - 輸入類型 文本字段