UIView 的使用

来源:互联网 发布:厦门继续教育网络平台 编辑:程序博客网 时间:2024/04/29 08:36

#pragma mark - /************************  getters setters view **************************/

/**

 *  setter getter view

 */

//============================"  UIView "=============================


//strong 创建view@property (nonatomic, strong) UIView *BgView;- (UIView *)BgView {    if (_BgView==nil) {        _BgView = [[UIView alloc] initWithFrame:CGRectMake(30, 20, SSWIDTH-60, 300)];        _BgView.backgroundColor = Yellow_COLOR;    }return _BgView;}//可以先添加,后调用[self.view addSubview:self.BgView];//weak 创建view@property (nonatomic, weak) UIView *BgView;- (UIView *)BgView {    if (_BgView==nil) {        UIView *BgView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, SSWIDTH, 50)];        [self.view addSubview:BgView];        _BgView = BgView;    }return _BgView;}//用self直接调用//添加多个 view- (void)addViewToSuperView:(UIView *)superView frame:(CGRect)frame tag:(NSInteger)tag{    UIView *myView = [[UIView alloc] initWithFrame:frame];    myView.tag= tag;    [superView addSubview:myView];    if (tag==111){        _view1 = myView;            }else if (tag==222){        _view2 = myView;            }else if (tag==333){        _view3 = myView;    }}


// 自定义view

- (instancetype)initWithFrame:(CGRect)frame {    self = [super initWithFrame:frame];    if (self) {        self.backgroundColor = [UIColor clearColor]; //iOS设置父视图透明度而不影响子视图        self.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];//TableView的背景    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; [self configUI];         }    return self;}- (instancetype)init {    self = [super init];    if (self) {[self configUI];    }    return self;}- (void)configUI { }



原创粉丝点击