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

做头像的网站深圳营销型网站建设推广服务

做头像的网站,深圳营销型网站建设推广服务,正规专业的互联网代做毕业设计网站,网络推广平台大全一、概念 链式编程风格是一种将多个函数调用连接起来,形成一条函数调用链的编程风格。这种风格的代码可以通过返回 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.yayakq.cn/news/689840/

相关文章:

  • 哪个网站可以做加工网站建设引擎
  • 唐山做网站企业网络营销常用工具有哪些?
  • 北京做企业网站多少钱wordpress4.9安装出错
  • 毕业设计(论文)-基于cms的校园网站建设js获取网站html
  • win7建网站教程vue做门户网站
  • 双德网站建设外贸网站建设谷歌推广
  • 建一个资源网站赚钱吗外国网站在中国做推广
  • 网站是先解析后备案wordpress 过滤get值
  • 网站内页制作做网站需要什么系统
  • 专门做男装的网站wordpress 不同文章不同模板
  • 学做网站看那个网内江网站建设
  • 中小型网站建设哪家好服务哪家好中医小程序定制
  • wordpress 头部引入jswordpress seo什么意思
  • 长沙天津网站建设移动网站开发与维护
  • 郧阳网站建设百度资源搜索平台官网
  • 网站动态添加广告怎么做的福州有网站建设的公司
  • 南昌有做网站的吗可以免费建设网站吗
  • 重庆建网站 私单巢湖市建设工程网站
  • 自己写代码做网站要什么技术网站页面怎么做导航
  • 开展农业信息网站建设工作总结建一个英文网站需要多少钱
  • 南宫做网站英文网站建设官网
  • 做网站的前端技术同城型网站开发
  • 外贸建站与推广如何做手机壳顺德网站设计制作
  • 网站建设制作设计seo优化山东汕头营销公司
  • 如何查询网站的建站工具湖南建设厅网站不良记录
  • 哪些网站可以做店铺推广阿帕奇网站搭建
  • 简述网站建设基本过程龙岩做网站改版一般多久
  • 不懂网站怎么做平台以前做视频的网站吗
  • 门户网站建设情况总结为什么买的网站模版不好用
  • 中国建设银行信用卡积分兑换网站网站建设论文 php