封裝Label,TextField

1.創(chuàng)建UIView
2.在UIView.h中創(chuàng)建兩個(gè)屬性

@property UILabel *aLabel;
@property UITextField *textField;

3.在UIView.m中重寫(xiě)初始化方法.創(chuàng)建新方法

//重寫(xiě)初始化方法
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
       
        [self setLabel];
        [self setTextField];
    }
    return self;
}
//模塊化創(chuàng)建label
//野指針 就是沒(méi)有指向確定空間的指針
- (void)setLabel {
    _aLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 40)];
    _aLabel.backgroundColor = [UIColor brownColor];
    _aLabel.textColor = [UIColor cyanColor];
    [self addSubview:_aLabel];
}
- (void)setTextField{
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(130, 10, 250, 40)];
    _textField.borderStyle = UITextBorderStyleRoundedRect;//默認(rèn)白色
    _textField.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:_textField];
}

4.在RootViewController.m的viewDidLoad中調(diào)用LTView

 LTView *aView = [[LTView alloc]initWithFrame:CGRectMake(10, 50, 390, 60)];
    aView.backgroundColor = [UIColor yellowColor];
    aView.aLabel.text = @"賬號(hào)";
    aView.textField.placeholder = @"請(qǐng)輸入賬號(hào)";
    [self.view addSubview:aView];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在iOS中隨處都可以看到絢麗的動(dòng)畫(huà)效果,實(shí)現(xiàn)這些動(dòng)畫(huà)的過(guò)程并不復(fù)雜,今天將帶大家一窺ios動(dòng)畫(huà)全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,687評(píng)論 6 30
  • 在iOS中隨處都可以看到絢麗的動(dòng)畫(huà)效果,實(shí)現(xiàn)這些動(dòng)畫(huà)的過(guò)程并不復(fù)雜,今天將帶大家一窺iOS動(dòng)畫(huà)全貌。在這里你可以看...
    F麥子閱讀 5,260評(píng)論 5 13
  • 1.OC里用到集合類是什么? 基本類型為:NSArray,NSSet以及NSDictionary 可變類型為:NS...
    輕皺眉頭淺憂思閱讀 1,469評(píng)論 0 3
  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會(huì)對(duì)里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,711評(píng)論 1 14
  • laod.cn
    jackieeji閱讀 150評(píng)論 0 0

友情鏈接更多精彩內(nèi)容