Should not modify global variable in function
If you have a function that returns a view, that’s great, but it should not, as a side product, modify a global variable. Functions should only change variables within their own scope and return a result.
The better way to code this is:
self.lockView = [self createLockView];
[self.view addSubview:self.lockView];
Globals are "bad" avoid them if you can.
Apple 推荐使用
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
因为这个是designated initializer;
Change the font of UITextView’s linkTextAttributes
We only have access to change the font color of UITextView’s linkTextAttributes, if we’d like to change the font of the link, we should just add attribute to the attributedString, for example
textView.linkTextAttributes = @{NSForegroundColorAttributeName : [UIColor linkColor]};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName : [UIColor defaultPanelBodyColor], NSFontAttributeName : [UIFont defaultPanelBodyFont]}];
[attributedString addAttributes:@{NSFontAttributeName : [UIFont linkTypeButtonFont]} range:linkRange];
[attributedString addAttributes:@{NSLinkAttributeName: kDefaultURL} range:linkRange];
本文讨论了在函数中避免修改全局变量的重要性,并提供了使用局部变量和返回视图的方法。同时,介绍了如何通过初始化方法正确设置文本视图链接字体,避免了直接修改全局变量的不当做法。
1224

被折叠的 条评论
为什么被折叠?



