Summary of various alignments of UI controls in IOS

Source: Internet
Author: User

1.textAligment: Alignment of the horizontal direction of the text
    • Take value
nstextalignmentleft      = < Span class= "Hljs-number" >0,    //left align nstextalignmentcenter    = 1,    //Center align nstextalignmentright    = 2,    //right-justified    
    • Which controls have this property
    • A control that is generally capable of displaying text has this property

      Uitextfield

      UILabel

      Uitextview ...

(UILabel is center-aligned by default and does not provide the top-aligned way-_-, which can be implemented in the following way:)

for(int i=0; i<newLinesToPad; i++) self.text = [self.text stringByAppendingString:@"\n "];

This method is more simple and rude, but effective. The method is to add more \ n after the text.
It is important to note that after \ n is added at least one space, otherwise the extra \ n will be ignored by Uilabel. From this point of view, Uilabel seems to be too "smart". Other ways to achieve label top alignment can be consulted: http://blog.devtang.com/2011/11/20/set-uilabel-text-align-top/

2.contentVerticalAlignment: Vertical alignment of content
    • Take value
UIControlContentVerticalAlignmentCenter  = 0, // 居中对齐UIControlContentVerticalAlignmentTop     = 1, // 顶部对齐UIControlContentVerticalAlignmentBottom  = 2, // 底部对齐

    • Which controls have this property

      A control that inherits from Uicontrol or Uicontrol itself

Uicontrol

UIButton

Uitextfield ...

3.contentHorizontalAlignment: Horizontal alignment of content
    • Take value
UIControlContentHorizontalAlignmentCenter = 0, // 居中对齐UIControlContentHorizontalAlignmentLeft   = 1, // 左对齐UIControlContentHorizontalAlignmentRight  = 2, // 右对齐

    • Which controls have these properties

A control that inherits from Uicontrol or Uicontrol itself

Uicontrol

UIButton

Uitextfield ....

More 2nd, the 3rd can be conveniently set btn text and pictures of various alignment, such as BTN settings:

Btn.contenthorizontalalignment = Uicontrolcontenthorizontalalignmentleft;

Btn.contentverticalalignment = Uicontrolcontentverticalalignmenttop;

The contents of the button are aligned at the top left corner.

4.contentMode: Content mode (controls how content is aligned), generally useful for Uiimageview
  • Take value

    Law:1.Scale: Picture will stretch2.Aspect: Picture will maintain the original aspect ratio3. Aspectscale */In the first 3 cases, the picture will stretch(default) stretches the picture to fill the entire uiimageview (the picture will be displayed in the same size as the Uiimageview)Uiviewcontentmodescaletofill,Scale to fit the entire uiimageview (the image cannot exceed the Uiimageview size range) According to the original aspect ratio of the image.Uiviewcontentmodescaleaspectfit,Stretch to the width of the picture as the width of the uiimageview or the height of the image as the height of the Uiimageview, as the image's original aspect ratio is scaled.Uiviewcontentmodescaleaspectfill,All subsequent cases will be displayed in the original size of the image and will not be stretchedUiviewcontentmoderedraw,When the size of the control changes, it is redrawn once (call Setneedsdisplay again, call DrawRect:)Uiviewcontentmodecenter,Uiviewcontentmodetop, uiviewcontentmodebottom, uiviewcontentmodeleft, uiviewcontentmoderight, Uiviewcontentmodetopleft, uiviewcontentmodetopright, uiviewcontentmodebottomleft, UIViewConten Tmodebottomright,       

    • Which controls have this property

      All UI controls have

It is important to note that: If there are multiple properties that conflict, only 1 properties are valid (nearest principle) (for example: BTN Contentmode and Contentverticalalignment are also set). Because the second constraint is directed against BTN, only the second property is valid!)

Summary of various alignments of UI controls in IOS

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.