iOS开发知识点 - 02

自定义UINavigationBar,并填充状态栏

效果图

1、自定义UINavigationBar
2、设置delegate
3、实现 UIBarPositioningDelegated的方法

func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
        return .TopAttached
}

UIButton按钮设置下划线

这里写图片描述


UITextView 或 UILabel加载HTML

NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://120.24.42.51:8080/BibiGoddess/UploadImages/admin/avatar/20160128c387f5bc-7a0e-4608-a90a-41312b4fa3b7.jpg' width=70 height=100 />";

// 转化成NSAttributedString
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

self.textView.attributedText = attributedString;
self.label.attributedText = attributedString;

UIImageView显示图片,只显示图片部分,不被压缩

imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;

绘制虚线

-(void)drawRect:(CGRect)rect {
    //设置虚线厚度
    CGFloat thickness = 1 * 0.8;
   
    CGContextRef cx = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(cx, thickness);
    CGContextSetStrokeColorWithColor(cx, [UIColor colorWithHexString:@"999999"].CGColor);
   
    CGFloat ra[] = {12,0};
    CGContextSetLineDash(cx, 0.0, ra, 3); 
   
    CGContextMoveToPoint(cx, 0,thickness*0.5);
    CGContextAddLineToPoint(cx, self.bounds.size.width, thickness*0.5);
    CGContextStrokePath(cx);
}

自定义UISegmentedControl字体颜色

let titleTextAttributes = [NSForegroundColorAttributeName: UIColor(hex: "333333")]

UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributes, forState: .Normal)

获取AFNetworking错误元数据

/// 获取错误码
public func WXGetAFResponseStringWithError(_ error: NSError?) -> String? {
    return (error?.userInfo["com.alamofire.serialization.response.error.data"] as? Data)?.stringValue
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄旺鑫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值