UIButton

code

UIButtonTypeSystem型,默認藍色

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeSystem];
    myButton.frame = CGRectMake(100, 200, 150, 50);
    [myButton setTitle: @"MyButton" forState: UIControlStateNormal];
    [self.view addSubview:myButton];
    [myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

- (void) buttonAction:(UIButton *) button {

}

image Button

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    myButton.frame = CGRectMake(100, 200, 150, 50);
    [myButton setImage:[UIImage imageNamed:@"圖片"] forState:UIControlStateNormal];
    [self.view addSubview:myButton];
    [myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

- (void) buttonAction:(UIButton *) button {

}

property

  • frame
  • tag
  • buttonType
  • currentTitle

method

addTarget:action:forControlEvents:
setTitle:forState:
setTitleColor:forState
setBackgroundImage:imageNamed:forState:
setImage:forState:

發佈了26 篇原創文章 · 獲贊 0 · 訪問量 5238
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章