iphone常用控件之UIButton

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    /*********按钮控件UIButton**********/
    
    UIButton *myButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect]; //按钮风格,6种
    myButton.frame =  CGRectMake(25.0, 25.0, 100.0, 100.0);
    
    //设置标题
    
    [myButton setTitle:@"Click Here"forState:UIControlStateNormal]; //平常状态
[myButton setTitle:@"Selected" forState:
UIControlStateSelected];//选中状态
    [myButton setTitle:@"Highlighted" forState:UIControlStateHighlighted]; //高亮
    myButton.showsTouchWhenHighlighted = YES;
//设置背景图像,设置后则只显示这个图片了
    
    //    [myButton setImage:[UIImage imageNamed:@"dealer_detail_background.png"] forState:UIControlStateNormal];
    
    //设置标题的颜色
    [myButton setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
    
    //设置标题的阴影
    [myButton setTitleShadowColor:[UIColorgrayColor] forState:UIControlStateNormal];
    
myButton.alpha = 0; //透明度
//设置按钮的背景 [myButton setBackgroundImage:[UIImageimageNamed:@"cartype.png"] forState:UIControlStateNormal]; myButton.adjustsImageWhenHighlighted = NO; //默认情况下,按钮按下时图像颜色变淡, 要禁用则设为NO myButton.adjustsImageWhenDisabled = NO; //默认情况下,按钮被禁用时图像颜色变深, 禁用则设为NO myButton.showsTouchWhenHighlighted = YES; //可令按钮在按下时发光。可用于信息按钮或重要的按钮 [self.view addSubview:myButton];//添加到当前view

     [self.viewbringSubviewToFront:myButton];//出现在最顶端


}
posted @ 2012-08-19 16:44  小、  阅读(465)  评论(0编辑  收藏  举报