iOS常用知识点总结(二)

一、修改电池导航栏颜色


iOS常用知识点总结(二)_第1张图片
021124078208620.png

二、调用代码使APP进入后台,达到点击Home键的效果。(私有API)

[[UIApplication sharedApplication] performSelector:@selector(suspend)];

三、修改textFieldplaceholder字体颜色和大小

textField.placeholder = @"请输入用户名"; 
 [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];

四、禁止textField和textView的复制粘贴菜单

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
    if ([UIMenuController sharedMenuController]) {
      [UIMenuController sharedMenuController].menuVisible = NO;
    } 
   return NO;
}

五、测划事件
测划返回触发的系统方法

- (void)willMoveToParentViewController:(UIViewController*)parent{
    [super willMoveToParentViewController:parent];
    NSLog(@"%s,%@",__FUNCTION__,parent);
    [self dismissKeyboard];
}
- (void)didMoveToParentViewController:(UIViewController*)parent{
    [super didMoveToParentViewController:parent];
    NSLog(@"%s,%@",__FUNCTION__,parent);
    if(!parent){
        NSLog(@"页面pop成功了");
    }
}

取消系统的返回手势

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

六、UIWebView在IOS9下底部出现黑边解决方式:
UIWebView底部的黑条很难看(在IOS8下不会,在IOS9会出现),特别是在底部还有透明控件的时候,隐藏的做法其实很简单,只需要将opaque设为NO,背景色设为clearColor即可

七、获取UIWebView的高度

(void)webViewDidFinishLoad (UIWebView *)webView  {
      CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
      CGRect frame = webView.frame;
      webView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);
  }

八、设置UILable 的行间距 和 计算带行间距的高度

/*
UILabel* 展示的控件
(NSString*)str  内容
withFont:(float)font 字体大小
WithSpace:(float)space 行间距
*/
//给UILabel设置行间距和字间距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(float)font WithSpace:(float)space{
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = space; //设置行间距
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
//设置字间距 NSKernAttributeName:@1.5f
UIFont *tfont = [UIFont systemFontOfSize:font];
NSDictionary *dic = @{NSFontAttributeName:tfont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
label.attributedText = attributeStr;
}
/*
计算UILabel的高度(带有行间距的情况)
(NSString*)str  内容
withFont:(float)font 字体大小
WithSpace:(float)space 行间距
(CGFloat)width  UILable的宽度
*/
//计算UILabel的高度(带有行间距的情况)
-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(float)font withWidth:(CGFloat)width WithSpace:(float)space{
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = space;
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
UIFont *tfont = [UIFont systemFontOfSize:font];
NSDictionary *dic = @{NSFontAttributeName:tfont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
CGSize size = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
return size.height;
}

九、键盘回收

    [self.view endEditing:YES];

10、图片阴影

    UIImageView *userImageView = [[UIImageView alloc] init];
    userImageView.backgroundColor = [UIColor whiteColor];
    userImageView.layer.cornerRadius = 7;
//    userImageView.layer.masksToBounds = YES;
    userImageView.layer.shadowColor = _Main_BlueColor.CGColor;
    userImageView.layer.shadowOpacity = 0.1f;
    userImageView.layer.shadowRadius = 5;
    userImageView.layer.shadowOffset = CGSizeMake(4,4);

11、webview莫名出现一条黑线

设置webview的属性opaque 可以解决
webview.opaque = NO;

持续更新~

你可能感兴趣的:(iOS常用知识点总结(二))