zoukankan      html  css  js  c++  java
  • UIButton

    作用:既能显示文字,也能显示图片

    状态:高亮,正常,按下

    内部:

    @property(nonatomic,readonly,retain)UILabel     *titleLabel NS_AVAILABLE_IOS(3_0);
    @property(nonatomic,readonly,retain)UIImageView *imageView  NS_AVAILABLE_IOS(3_0);
    链接:https://www.jianshu.com/p/0fd782d67efb

    有一个imageView和label

    创建UIButton:

    IButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];  //等价 UIButton *btn = [[UIButton alloc] init];
    //在btn被按下时,会调用buttonClick方法
    [btn addTarget:self action:@selector(buttonClick) forCOntrolEvents:UIControlEventTouchUpInside];
    //带参数的监听方法
    [btn addTarget:self action:@selector(buttonClick:) forCOntrolEvents:UIControlEventTouchUpInside];

    按钮来实现图片上文字下的效果

    第一种:

    -(CGRect)titleRectForContentRect:(CGRect)contentRect{
    
            // 返回文字的frame   
    
     }
    
    -  (CGRect)imageRectForContentRect:(CGRect)contentRect{
    
            // 返回图片的frame
    
     }

    第二种 

    重写layoutSubViews方法

    第三种 按钮的内边距:

     self.btn.contentEdgeInsets = UIEdgeInsetsMake(30, 30, 0, 0);
    
     self.btn.titleEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    
     self.btn.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
  • 相关阅读:
    toj 2975 Encription
    poj 1797 Heavy Transportation
    toj 2971 Rotating Numbers
    zoj 2281 Way to Freedom
    toj 2483 Nasty Hacks
    toj 2972 MOVING DHAKA
    toj 2696 Collecting Beepers
    toj 2970 Hackle Number
    toj 2485 Card Tric
    js页面定位,相关几个属性
  • 原文地址:https://www.cnblogs.com/wwjwb/p/12644153.html
Copyright © 2011-2022 走看看