细节总结170601

导航栏图片按钮变色导致图片变色

在把图片添加到导航栏的时候,图片的颜色会根据导航栏的tintcolor而改变其原来的颜色,这时候可以设置图片的展示方式为原始的样式即可

1
UIImage *image = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

button设置文字会跳动

当一个button设置了imagetitle,如果我们快速的修改其title,那么就会出现title会一闪一闪的跳动,可以这样来解决

1
2
3
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.text = @"text";
[button setTitle:@"text" forState:UIControlStateNormal];

cell上的视图背景色在长按的时候会消失

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
self.backgroundColor = kFTFContentBgColor;
// 解决cell高亮、选择后的背景色
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
self.selectedBackgroundView.backgroundColor = FTFColorHex(0x1B1D25);
self.customSelectedBackgroundView = [[UIView alloc] init];
self.customSelectedBackgroundView.backgroundColor = kFTFOpenedCellBackgroundColor;
self.customSelectedBackgroundView.hidden = YES;
[self addSubview:self.customSelectedBackgroundView];
[self initlization];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.selectedBackgroundView.frame = self.bounds;
self.customSelectedBackgroundView.frame = self.bounds;
}

cell上的view颜色在选中的时候会变色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
[self configOriginalBackgroundColorForView:self];
}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
[self configOriginalBackgroundColorForView:self];
}
- (void)configOriginalBackgroundColorForView:(UIView *)view
{
for (id obj in view.subviews) {
if ([obj isKindOfClass:[UIView class]]) {
UIView *subview = (UIView *)obj;
if (subview.cachedColor) {
subview.backgroundColor = subview.cachedColor;
}
[self configOriginalBackgroundColorForView:obj];
}
}
}

xcode9导出APP时出错

在xcode9打包APP打出的时候出现这样的错误:

1
2
Stripping extended attributes failed.
"/usr/bin/xattr -crs /var/folders/mm/h01jykrs7gv9w7jjb0yt609w0000gp/T/XcodeDistPipeline.Uay/Root/Payload/GitSmartHome.app" exited with a non-zero status. The /usr/bin/xattr tool may be damaged.

stackoverflow上找到的答案

wkwebviewcookie传递问题

在使用WKWebView的时候,需要往网页中传递一些cookie数据,但是由于在WKWebView中,调用JS是一种异步的操作,所以会出现在初始化网页的时候,cookie传递失败的问题。
可以在初始化webview的时候,初始化一个WKUserContentController,并直接注入cookie

1
2
WKUserScript *script = [[WKUserScript alloc] initWithSource:[NSString stringWithFormat:@"document.cookie='portal_login_token=%@;path=/;domain=%@'", [FTFUserManager sharedManager].accessToken, [FTFAPIConfig sharedInstance].webCookieDomain] injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
[self.contentController addUserScript:script];