UIButton

这两种方法创建出来是一样的,因为系统默认是system,自定义按钮则就是Custom
UIButton *addBtn = [UIButton buttonWitnType:UIButtonTypeCustom];
UIButton *addBtn = [[UIButton alloc] init];
设置按钮背景图片

注意:按钮touchesBegan和监听方法会冲突

UIButton、UIImageView、UILabel的选择

  • 能用UIImageView或者UILabel就不用UIButton

  • 只要继承UIControl就有addTarget...方法监听事件

    UIButton:
          能显示两张图片(背景,内容图片)和文字
          长按高亮时可切换图片或文字
          直接通过addTarget...方法监听点击
    
  • 按钮的enable属性YES会让按钮变灰色,user...enable则不会,并且不接受点击事件。
UIImageView:
        能显示图片
        不能通过addTarget...方法监听点击
 下面两段代码含义一样
>>>>
   UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"wzsam"];
    imageView.frame= CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height);
>>>>
    UIImageView *imageView = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"wzsam"];
UILabel:
        能显示文字
        不能通过addTarget...方法监听点击
    // 可以提前拿到按钮内部label的尺寸
    [button.titleLabel sizeToFit];

results matching ""

    No results matching ""