iOSの開発シリーズ-UIButtonの使用概要

2378 ワード

//    button     
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

//      UIButton     6 :
//    typedef enum {
//        UIButtonTypeCustom = 0,                
//        UIButtonTypeRoundedRect,             
//        UIButtonTypeDetailDisclosure,         button,        
//        UIButtonTypeInfoLight,                
//        UIButtonTypeInfoDark,                 
//        UIButtonTypeContactAdd,              button
//    } UIButtonType;

//   button     
btn.frame = CGRectMake(20, 360, 280, 45);
//   button    
btn.backgroundColor = [UIColor colorWithRed:254/255.0f green:254/255.0f blue:254/255.0f alpha:1.0f];
//   button  
[btn setTitle:@"Normal" forState:UIControlStateNormal];
[btn setTitle:@"Pressed" forState:UIControlStateHighlighted];

// forState          button                ,       :
//    enum {
//        UIControlStateNormal       = 0,                 
//        UIControlStateHighlighted  = 1 << 0,            
//        UIControlStateDisabled     = 1 << 1,               
//        UIControlStateSelected     = 1 << 2,          
//        UIControlStateApplication  = 0x00FF0000,          
//        UIControlStateReserved     = 0xFF000000          ,     
//    };

//   button    
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//   button    
[btn.titleLabel setFont:[UIFont systemFontOfSize:17]];
[btn.layer setMasksToBounds:YES];
//   button      
[btn.layer setCornerRadius:4.0];
//   button    
[btn.layer setBorderWidth:0.5];
//   button    
CGColorRef colorref = CGColorCreate(CGColorSpaceCreateDeviceRGB(),(CGFloat[]){168/255.0f, 168/255.0f, 168/255.0f, 1.0});
[btn.layer setBorderColor:colorref];
//   button           
tableView.delaysContentTouches = NO;
//       
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];

//       button
[tableView addSubview:btn];

// button    
- (void)btnAction:(id)sender
{
    // do something
}
本明細書の固定リンク:http://www.itechzero.com/ios-development-series-one-uibutton-usage-summary.html.転載は出典を明記してください.
本文のブログのオリジナルの文章、ブログ、同意を得ないで、転載してはいけません.