Ios-uilabel is centered with the content, followed by the control followed by the

Source: Internet
Author: User

Green and blue box, Uilabel display name, label box with the length of the name and adaptive, followed by the gender image followed by the display

Divided into two parts: first Part first layout

Name

Self.namelab = [[UILabel alloc]initwithframe:cgrectmake (0, Screen_width, 20)];

Self.nameLab.textColor = [Uicolor Whitecolor];

Self.nameLab.font = [Uifont fontwithname:@ "Helvetica-blod" size:19];

Self.nameLab.textAlignment = Nstextalignmentcenter;

Self.nameLab.backgroundColor = [Uicolor Clearcolor];

[SELF.BGV AddSubview:self.nameLab];

Gender

Self.seximageview = [[Egoimageview alloc]init];

[SELF.BGV AddSubview:self.sexImageView];

The second part of the analysis of the data, according to the content of the adaptive width, and then reset the location of the gender picture

Self.nameLab.text = self.membernmstr;//Name

[Self.namelab SizeToFit];

Cgsize size = [Self.nameLab.text sizewithfont:[uifont systemfontofsize:19] Constrainedtosize:cgsizemake (screen_width , linebreakmode:nslinebreakbywordwrapping];

CGRect r1 = self.nameLab.frame;

R1.size.width = Size.width;

Self.nameLab.frame = R1;

Self.nameLab.center = Cgpointmake (SELF.BGV.FRAME.SIZE.WIDTH/2, 130+10);

[Self.seximageview setframe:cgrectmake (self.nameLab.frame.size.width + self.nameLab.frame.size.width + 10, 130, 20, 20 )];

CGRect r2 = self.sexImageView.frame;

r2.origin.x = self.namelab.frame.origin.x + ten + self.nameLab.frame.size.width;

Self.sexImageView.frame = R2;

Ios-uilabel is centered with the content, followed by the control followed by the

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.