当前位置: 首页 > news >正文

51自学网个人seo外包

51自学网,个人seo外包,苏州高端做网站,帮客户做ppt什么的在哪个网站一、概念 链式编程风格是一种将多个函数调用连接起来,形成一条函数调用链的编程风格。这种风格的代码可以通过返回 self 或某个适当的对象来实现。 1.优点 代码简洁、连贯、易于阅读。可以将一个方法的输出直接作为下一个方法的输入,降低中间变量的使…

一、概念

链式编程风格是一种将多个函数调用连接起来,形成一条函数调用链的编程风格。这种风格的代码可以通过返回 self 或某个适当的对象来实现。

1.优点

  1. 代码简洁、连贯、易于阅读。
  2. 可以将一个方法的输出直接作为下一个方法的输入,降低中间变量的使用。

2.缺点

  1. 链式调用过长可能会导致代码可读性降低。
  2. 由于错误可能出现在链的任何一环,所以调试可能会有所困难。

二、代码

下面是一个使用链式编程风格构建的 NSMutableAttributedString 的例子,这个例子将展示如何将一系列的 NSAttributedString 配置操作链接在一起。

首先,我们需要创建一个类 ChainableAttributedBuilder,它可以用于创建和配置 NSAttributedString:

1..h文件

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface ChainableAttributedBuilder : NSObject

@property (nonatomic, strong, readonly) NSMutableAttributedString *mutableAttributedString;

- (ChainableAttributedBuilder *(^)(NSString *text))append;

- (ChainableAttributedBuilder *(^)(UIColor *color))textColor;

- (ChainableAttributedBuilder *(^)(UIFont *font))font;

- (ChainableAttributedBuilder *(^)(NSParagraphStyle *style))paragraphStyle;

@end

NS_ASSUME_NONNULL_END

2..m文件

#import "ChainableAttributedBuilder.h"

@implementation ChainableAttributedBuilder

- (instancetype)init {

    if (self = [super init]) {

        _mutableAttributedString = [[NSMutableAttributedString alloc] init];

    }

    return self;

}

- (ChainableAttributedBuilder *(^)(NSString *text))append {

    return ^(NSString *text) {

        NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];

        [self.mutableAttributedString appendAttributedString:attributedString];

        return self;

    };

}

- (ChainableAttributedBuilder *(^)(UIColor *color))textColor {

    return ^(UIColor *color) {

        [self.mutableAttributedString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, self.mutableAttributedString.length)];

        return self;

    };

}

- (ChainableAttributedBuilder *(^)(UIFont *font))font {

    return ^(UIFont *font) {

        [self.mutableAttributedString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.mutableAttributedString.length)];

        return self;

    };

}

- (ChainableAttributedBuilder *(^)(NSParagraphStyle *style))paragraphStyle {

    return ^(NSParagraphStyle *style) {

        [self.mutableAttributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, self.mutableAttributedString.length)];

        return self;

    };

}

@end

3.调用代码

    ChainableAttributedBuilder *builder = [[ChainableAttributedBuilder alloc] init];

    builder.append(@"Hello ").font([UIFont systemFontOfSize:16]).textColor([UIColor redColor]);

    builder.append(@"world!").font([UIFont systemFontOfSize:20]).textColor([UIColor blueColor]);

    NSAttributedString *attributedString = builder.mutableAttributedString;

    // 现在,attributedString 是一个带有不同样式的 "Hello world!" 的富文本字符串。

http://www.fp688.cn/news/152915.html

相关文章:

  • 怎么做婚介网站免费收录网站推广
  • 广东广州自己建网站公司吸引人的软文标题
  • 厦门35网站建设公司新手怎么做网页
  • 马鞍山网站建设设计seo搜索引擎推广
  • 百度手机网页南昌seo排名优化
  • 本地做网站教程方象科技的服务范围
  • 天府新区规划建设国土局网站河南做网站优化
  • 龙港做网站店铺网站运营怎么做
  • 衡水移动网站建设报价seo关键词排名实用软件
  • 深圳网站建设公司简介软文推广多少钱一篇
  • 网站备案号省份南昌关键词优化软件
  • 英文专业的网站设计国家培训网官网
  • 自己做了一个网站seo外包公司兴田德润官方地址
  • 2019年做网站网页快速收录
  • 深圳网站建设的公司网络营销现状分析
  • 网站网页设计原则百度知道网址
  • 广州东莞网站建设百度浏览器官方网站
  • 网站建设制作游戏优化是什么意思
  • 网站侧边栏导航代码seo实战密码第四版pdf
  • 做网站不给维护属于诈骗吗武汉关键词排名推广
  • 还有用的网站软文推广经典案例
  • 免费社区建站系统短视频代运营方案模板
  • 个人网站备案怎么写家居seo整站优化方案
  • 广东专业网站建设5g网络优化工程师
  • 网站开发学些什么软件个人网站推广平台大全
  • 福州专业做网站公司网络营销师课程
  • 龙华网站建设哪家好站长seo综合查询
  • 兰州网站推广优化网站营销策略
  • 企业品牌网站建设的关键事项郑州网站开发顾问
  • 好的网站建设技术业务网站制作