storyboard的怎么复制粘贴图层

storyboard的怎么复制粘贴图层,第1张

storyboard的怎么复制粘贴图层,在iOS中有三个控件自身就有复制-粘贴的功能:UITextView、UITextField和UIWebView。在这里,我们自定义一个button简单地实现将label中的文字复制到粘贴板中。

首先创建一个工程,命名为CopyToClipboardDemo。打开工程,我们在storyboard中添加一个label和button,label中显示的是我们要复制的文字

.h

NS_ASSUME_NONNULL_BEGIN

@interface GHAttributesLabel : UILabel

typedef void(^GHAttributesBlock)(NSRange poinRange)

/**

@param text 传入富文本类型的字符串

@param actionText 要响应事件的字符串

*/

/**

点击事件回调

*/

@property (nonatomic , copy) GHAttributesBlock actionBlock

.m

//

// GHAttributesLabel.m

// GHAttributesLabelDemo

//

// Created by zhaozhiwei on 2019/1/20.

// Copyright © 2019年 GHome. All rights reserved.

//

@interface GHTextView : UITextView

@end

@implementation GHTextView

@end

@interface GHAttributesLabel()<UITextViewDelegate>

@property (nonatomic , strong) GHTextView *textView

@property (nonatomic , copy) NSString *actionText

/** <#注释#>*/

@property (nonatomic, assign) NSRange range

@end

@implementation GHAttributesLabel

//return YES

}

@end

使用

-(void)test{

GHAttributesLabel *attributesLabel = [[GHAttributesLabel alloc]initWithFrame:CGRectMake(10, 200, [UIScreen mainScreen].bounds.size.width - 20, 250)]

//NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:temp]

// NSRange range = [temp rangeOfString:actionStr]

//NSLog(@"range%@",NSStringFromRange(range))

NSArray *actionArr = [self rangeOfSubString:actionStr inString:temp]

NSLog(@"===:%@",[self rangeOfSubString:actionStr inString:temp])

for (int i = 0i <actionArr.counti++) {

NSValue *value = actionArr[i]

NSRange actionRange = [value rangeValue]

[attrStr addAttribute:NSLinkAttributeName

value:actionStr

range: actionRange]

}

}

}

return rangeArray

}

-(NSMutableAttributedString *)keyWords:(NSString *)keyWords withKeyWordsColor:(UIColor *)color

{

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11642173.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存