首页 > 代码库 > 开发细节(三)

开发细节(三)

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;//设置边框的宽度为20self.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;}

 

开发细节(三)