鏈?zhǔn)骄幊?函數(shù)編程---iOS筆記摘錄

鏈?zhǔn)骄幊?/h5>
增強(qiáng)可讀性(通過.將所有操作通過一行代碼搞定)

  UILabel
  其他控件(見工具庫)

UILabel

使用

 UILabel *nameL=YLable.yfont(UIFont(20)).ytextColor(RGBOF(0xffffff)).InView(headView);

UILabel+LinkBlock.h

#import <UIKit/UIKit.h>

#define   YTLable    [UILabel new]

@interface UILabel (LinkBlock)

+(UILabel *)Init;
- (UILabel * (^)(CGRect bounds))ybounds;
- (UILabel * (^)(CGRect frame))yframe;
- (UILabel * (^)(UIView *View))InView;

- (UILabel * (^)(NSString *text))ytext;
- (UILabel * (^)(UIFont *font))yfont;
- (UILabel * (^)(UIColor *textColor))ytextColor;
- (UILabel * (^)(NSTextAlignment textAlignment))ytextAlignment;

- (UILabel * (^)(NSInteger numberOfLines))ynumberOfLines;
- (UILabel * (^)(UIColor *backgroundColor))ybackgroundColor;
- (UILabel * (^)(NSAttributedString *attributedText))yattributedText;
- (UILabel * (^)(CGFloat cornerRadius))ycornerRadius;
@end

UILabel+LinkBlock.m

#import "UILabel+LinkBlock.h"

@implementation UILabel (LinkBlock)

+(UILabel *)Init{
    
    return [[UILabel alloc] init];
}


// bounds
- (UILabel * (^)(CGRect bounds))ybounds{
    return ^id(CGRect ybounds){
        self.bounds= ybounds;
        return self;
    };
}
// frame
- (UILabel * (^)(CGRect frame))yframe{
    return ^id(CGRect yframe){
        self.frame= yframe;
        return self;
    };
}
// text
- (UILabel * (^)(NSString *text))ytext{
    return ^id(NSString  *ytext){
        self.text=ytext;
        return self;
    };
}
// color
- (UILabel * (^)(UIColor *textColor))ytextColor{
    return ^id(UIColor *ytextColor ){
        self.textColor=ytextColor;
        return self;
    };
}
// font
- (UILabel * (^)(UIFont *font))yfont{
    return ^id(UIFont *yfont){
        self.font= yfont;
        return self;
    };
}
// textAlignment
- (UILabel * (^)(NSTextAlignment textAlignment))ytextAlignment{
    return ^id(NSTextAlignment  ytextAlignment){
        self.textAlignment=ytextAlignment;
        return self;
    };
}
// numberOfLines
- (UILabel * (^)(NSInteger numberOfLines))ynumberOfLines{
    return ^id(NSInteger ynumberOfLines ){
        self.numberOfLines=ynumberOfLines;
        return self;
    };
}
// backgroundColor
- (UILabel * (^)(UIColor *backgroundColor))ybackgroundColor{
    return ^id(UIColor *ybackgroundColor ){
        self.backgroundColor=ybackgroundColor;
        return self;
    };
}
// attributedText
- (UILabel * (^)(NSAttributedString *attributedText))yattributedText{
    return ^id(NSAttributedString  *yattributedText){
        self.attributedText=yattributedText;
        return self;
    };
}
// cornerRadius
- (UILabel * (^)(CGFloat cornerRadius))ycornerRadius{
    return ^id(CGFloat  ycornerRadius){
        self.layer.cornerRadius=ycornerRadius;
        self.layer.masksToBounds=YES;
        return self;
    };
}
// add in SupperView
- (UILabel * (^)(UIView *View))InView{
    return ^id(UIView  *InView){
        [InView addSubview:self];
        return self;
    };
}
@end
函數(shù)編程
函數(shù)做完操作后,返回對象本身。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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