iOS Learning-11. Rounded corners (less than or equal to four) similar to bubbles and calculated character Heights

Source: Internet
Author: User

Using Bezier curves,

//less than four fillet corners-(void) setbor{NSString*str =@"couldn ' t fit this all in a comment to @lomanf ' s answer. So I ' m adding it as an answer."; //Calculate character Height[Corner LayoutHeightWithLable:self.label text:str]; /*1. Use Blank view Addsubview label 2. Get similar QQ chat bubbles, just like, or there is a difference*/UIView*view =[[UIView alloc]init]; //the frame of the view is larger than the label, or the fillet is cut to the stringView.frame = CGRectMake ( -, -, _label.frame.size.width + -, _label.frame.size.height + -); View.backgroundcolor=[Uicolor Redcolor]; //Rounded Corners[Corner Createcornerinview:view corners:uirectcornerbottomleft| Uirectcornertopright Cgsize:cgsizemake (Ten,Ten)];    [Self.view Addsubview:view]; [View Addsubview:_label];}

A new class was created: Corner

. h

#import <UIKit/UIKit.h>@interface  corner:uiview+ (void) Createcornerinview: (UIView *) View Corners: (uirectcorner) Corner cgsize: (cgsize) size; + (void) layoutheightwithlable: (UILabel *) label text: (NSString *) text; @end

. m

+(void) Layoutheightwithlable: (UILabel *) label text: (NSString *) text{Label.numberoflines=0; Label.linebreakmode=nslinebreakbywordwrapping; Cgsize maxSize= Cgsizemake ( -, maxfloat); Cgsize textSize= [Text boundingrectwithsize:maxsize options: (nsstringdrawingusesfontleading |nsstringdrawinguseslinefragmentorigin) Attributes:@{nsfontattributename:label.font} context:nil].size; Label.frame=CGRectMake (label.frame.origin.x, LABEL.FRAME.ORIGIN.Y, Textsize.width, textsize.height); Label.text=text;}+(void) Createcornerinview: (UIView *) View Corners: (uirectcorner) Corner cgsize: (cgsize) size{/*typedef ns_options (Nsuinteger, uirectcorner) {uirectcornertopleft = 1 << 0,-upper left corner Uirectcorne Rtopright = 1 << 1,-upper right corner uirectcornerbottomleft = 1 << 2,-lower left corner uirectcornerbottomright = 1 <     ;< 3,-lower right corner uirectcornerallcorners = ~0ul-Four Corners}; */    //Bezier CurveUibezierpath *bezierpath =[Uibezierpath bezierPathWithRoundedRect:view.bounds byroundingcorners:corner cornerradii:size]; Cashapelayer*masklayer =[[Cashapelayer alloc]init]; Masklayer.frame=View.bounds; Masklayer.path=Bezierpath.cgpath; View.layer.mask=Masklayer;}

iOS Learning-11. Rounded corners (less than or equal to four) similar to bubbles and calculated character Heights

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.