Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.8 更新日志 #20

Open
3 tasks done
xaoxuu opened this issue May 29, 2017 · 0 comments
Open
3 tasks done

0.0.8 更新日志 #20

xaoxuu opened this issue May 29, 2017 · 0 comments

Comments

@xaoxuu
Copy link
Owner

xaoxuu commented May 29, 2017

NSString+

字符串其实可以干更多事

  • 转URL
  • 判断是不是URL
  • 转Image
- (nullable NSURL *)absoluteURL;

- (BOOL)isURLString;

- (nullable UIImage *)image;

例如我们获取到一个"URLString",用来显示用户头像

NSString *tmp = @"https://xaoxuu.com/images/avatar.png";
// 需要用到URL的话,就是tmp.absoluteURL
// 需要判断它是不是合法的URL就
if (tmp.isURLString) {
  // 是URL
} else {
  // 不是URL
}

例如资源图片名为"test.png"

// 有一个ImageView名为imgv
imgv.image = @"test".image;

做了一点简单的封装,让代码更简单

隐藏系统自带的NavigationBar/TabBar分割线?

两个类都添加了一个移除分割线的方法:

/**
 移除系统自带的分割线
 */
- (void)ax_hideSeparator;

注意:分割线不是一开始就有的,因此建议都写在- viewDidLayoutSubviews中。

使用示例:

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self.tabBar ax_hideSeparator];
}

判断颜色是深色还是浅色?

/**
 粗略判断颜色是不是浅色调

 @return 是不是浅色
 */
- (BOOL)isLightColor;

例如判断背景颜色是浅色的话,文字颜色设为主题色,如果背景颜色是深色的话,文字颜色为白色:

// 假设view上面有一个label
if (view.backgroundColor.isLightColor) {
    label.textColor = axColor.theme;
} else {
    label.textColor = axColor.white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant