开发细节(三)

1. UIWebView修改加载页面的字体大小及其它属性

通过实现UIWebViewDelegate的- (void)webViewDidFinishLoad:(UIWebView *)webView来实现

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSLog(@"webViewDidFinishLoad");
    //字体大小
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '120%'"];
    //字体颜色
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];
    //页面背景色
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
}

2. 代码实现圆角UIImageView

self.avatarImageView.image = [UIImage imageNamed:@"AvatarDefaultIcon"];

//告诉layer将位于它之下的layer都遮盖住
self.avatarImageView.layer.masksToBounds = YES;

//设置layer的圆角,刚好是自身宽度的一半,这样就成了圆形
self.avatarImageView.layer.cornerRadius = self.avatarImageView.bounds.size.width * 0.5;

//设置边框的宽度为20
self.avatarImageView.layer.borderWidth = 1.0;

//设置边框的颜色
self.avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;

3. JS与iOS互调

iOS调用JS

iOS端
JS端

JS调用iOS

iOS端
JS端

4. UITableView按内容确定高度

Code

5. 修改导航栏字体颜色

iOS10以后有一些变化,先设置:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

如果在Attributes Inspector设置了Navigation Bar的"Bar Tint",则上面设置将失效,这个时候需要在

didFinishLaunchingWithOptions里调用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [UINavigationBar appearance].barStyle = UIBarStyleBlackOpaque;
    return YES;
}

 

posted @ 2017-02-19 14:08  CoderWayne  阅读(323)  评论(0编辑  收藏  举报