【简单常用】button

来源:互联网 发布:万方专利数据库 编辑:程序博客网 时间:2024/05/09 23:42

    UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeSystem];

    //UIButtonTypeCustom   自定义风格(无边框的那种)默认

    //UIButtonTypeSystem   圆角


    button1.frame =CGRectMake(100,100,50,50);

   

    [button1 setTitle:@"BTN1"forState:UIControlStateNormal];//样式

    

    [button1 setTitleColor:[UIColorredColor] forState:UIControlStateNormal];

    button1.titleLabel.textColor=[UIColor yellowColor];    //字体颜色,同上

    

    button1.titleLabel.textAlignment=NSTextAlignmentRight;      //对齐方式靠右


    button1.titleLabel.font=[UIFontboldSystemFontOfSize:16];  //字体加粗16


    

//点击事件

    [button1 addTarget:selfaction:@selector(qh)forControlEvents:UIControlEventTouchUpInside];

    [button1 setTitleShadowColor:[UIColorgrayColor] forState:UIControlStateNormal];//阴影

    

//高亮时的 图片

    [button1 setBackgroundImage:[UIImageimageNamed:@"P"]forState:UIControlStateHighlighted];

    

   //内容到边缘距离(上左下右)

    button1.contentEdgeInsets =UIEdgeInsetsMake(0,10,0,0);

    button1.titleEdgeInsets=UIEdgeInsetsMake(0,10,0,0);

    button1.imageEdgeInsets=UIEdgeInsetsMake(0,10,0,0);

    

   //图片随按钮高亮而高亮,默认YES

    button1.adjustsImageWhenHighlighted =NO;

    

   //图片随按钮失效而变暗,默认YES

    button1.adjustsImageWhenDisabled=NO;

    

   //按下会有白色光点,默认NO

    button1.showsTouchWhenHighlighted=YES;

    

0 0
原创粉丝点击