zoukankan      html  css  js  c++  java
  • 改变UIButton上标题位置、文字颜色、背景色等

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
      
      //添加点击事件
      [button addTarget:self action:@selector(pushToSecond) forControlEvents:UIControlEventTouchUpInside];
      
      //整个按钮的背景色(无背景图片时有效果)
      button.backgroundColor = [UIColor greenColor];
      
      //添加背景图片
      [button setBackgroundImage:[UIImage imageNamed:@"01.png"] forState:UIControlStateNormal];
      
      //按钮标题
      [button setTitle:@"Hello World!" forState:UIControlStateNormal];
      
      //button上子控件的水平对齐方式
      button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
      
      //button上子控件的垂直对齐方式
      button.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
      
      //内容容器的偏移,让文字向右偏移20像素
      button.contentEdgeInsets = UIEdgeInsetsMake(0,20, 0, 0);
      
      //设置标题的背景颜色
      button.titleLabel.backgroundColor = [UIColor purpleColor];
      
      //标题颜色
      [button setTitleColor:[UIColor yellowColor]forState:UIControlStateNormal];
      
      button.imageView.contentMode = UIViewContentModeScaleAspectFit;
      
      [self.view addSubview:button];
      [button release];
    喝最烈的酒,看最美的风景。
  • 相关阅读:
    VlanTrunk
    2015届互联网名企校招网址一览表
    The declared package does not match the expected package
    经典的算法网站
    Nutch
    JTable只要一双击就进入编辑状态,禁止的方法实现
    Java通过JDBC链接数据库,数据库中wen
    Cisco Packet Tracer的使用(一)
    Nutch安装的几个网址
    面试经
  • 原文地址:https://www.cnblogs.com/mona/p/4224251.html
Copyright © 2011-2022 走看看