美文网首页
2018-01-10

2018-01-10

作者: chaochaoMaiTian | 来源:发表于2018-02-28 00:23 被阅读0次

    多变的UI设计的Tips1,保留一份以后可能会用

    +(UIView *)labelWithString:(NSString *)string point:(CGPoint)point location:(KrcLocation)location{ UIView *view = [UIView new]; CGFloat h = AdaW(44); CGFloat w = 0; CGFloat r = 2; UIFont *font = AdaFont(14); CGSize size = [string boundingRectWithSize:CGSizeMake(SCREEN_WIDTH, h) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size; size = CGSizeMake(size.width + AdaW(40), size.height); w = size.width; CGRect laFrame = CGRectMake(0, 0, w, h); UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:laFrame cornerRadius:r]; // 三角的位置 if (location == Location_UP) { laFrame.origin.y = point.y; // [path moveToPoint:CGPointMake(0 , r)]; // [path addArcWithCenter:CGPointMake(r, r) radius:r startAngle:M_PI endAngle:M_PI_2 * 3 clockwise:YES]; if (point.x > SCREEN_WIDTH *.5) { // x1 = size.width - (SCREEN_WIDTH - AdaW(16)-AdaW(10) - point.x); laFrame.origin.x = SCREEN_WIDTH - AdaW(16)-AdaW(10) - w; }else{ // x1 = point.x - AdaW(26); laFrame.origin.x = AdaW(26); } // [path addLineToPoint:CGPointMake(x1, 0)]; // [path addLineToPoint:CGPointMake(x1 + 4, 0)]; // [path addLineToPoint:CGPointMake(x1 + 8, 0)]; // [path addLineToPoint:CGPointMake(w-r, 0)]; // [path addArcWithCenter:CGPointMake(w-r, r) radius:r startAngle:M_PI_2 * 3 endAngle:0 clockwise:YES]; // [path addLineToPoint:CGPointMake(w, h-r)]; // [path addArcWithCenter:CGPointMake(w-r, h-r) radius:r startAngle:0 endAngle:M_PI_2 clockwise:YES]; // // [path addLineToPoint:CGPointMake(r, h)]; // [path addArcWithCenter:CGPointMake(r, h-r) radius:r startAngle:M_PI_2 endAngle:M_PI clockwise:YES]; // [path addLineToPoint:CGPointMake(0 , r)]; }else{ laFrame.origin.y = point.y - h; // [path moveToPoint:CGPointMake(0 , r)]; // [path addArcWithCenter:CGPointMake(r, r) radius:r startAngle:M_PI endAngle:M_PI_2 * 3 clockwise:YES]; // [path addLineToPoint:CGPointMake(w-r, 0)]; // [path addArcWithCenter:CGPointMake(w-r, r) radius:r startAngle:M_PI_2 * 3 endAngle:0 clockwise:YES]; // [path addLineToPoint:CGPointMake(w, h-r)]; // [path addArcWithCenter:CGPointMake(w-r, h-r) radius:r startAngle:0 endAngle:M_PI_2 clockwise:YES]; // CGFloat x1; if (point.x > SCREEN_WIDTH *.5) { // x1 = size.width - (SCREEN_WIDTH - AdaW(16)-AdaW(10) - point.x ); laFrame.origin.x = SCREEN_WIDTH - AdaW(16)-AdaW(10) - w; }else{ // x1 = point.x - AdaW(26); laFrame.origin.x = AdaW(26); } // [path addLineToPoint:CGPointMake(x1 + 8, h)]; // [path addLineToPoint:CGPointMake(x1 + 4, h )]; // [path addLineToPoint:CGPointMake(x1, h)]; // [path addLineToPoint:CGPointMake(r, h)]; // [path addArcWithCenter:CGPointMake(r, h-r) radius:r startAngle:M_PI_2 endAngle:M_PI clockwise:YES]; // [path addLineToPoint:CGPointMake(0 , r)]; } UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(AdaW(2), h - AdaW(10), w - AdaW(4), AdaW(20)) cornerRadius:AdaW(10)]; CAShapeLayer *layer = [CAShapeLayer layer]; layer.path = path.CGPath; layer.fillColor = kTipsBgColor.CGColor; layer.shadowPath = shadowPath.CGPath; layer.shadowColor = [UIColor blackColor].CGColor; layer.shadowOpacity = 0.7; UILabel *la = [[UILabel alloc]initWithFrame:laFrame]; [la.layer addSublayer:layer]; la.font = font; la.textColor = [UIColor whiteColor]; la.textAlignment = NSTextAlignmentCenter; la.text = string; return view; }

    相关文章

      网友评论

          本文标题:2018-01-10

          本文链接:https://www.haomeiwen.com/subject/zigonxtx.html