Attributes of UITextField and UILabel in mono touch

Source: Internet
Author: User

UILabel is vertically centered by default, and the height of UITextField is in the center, but this is not the case. It is set to the top (of course, there is a default padding similar to css, so how can we make it center by the height compromise? The verticalignment attribute can be [csharp] UITextField utxt = new UITextField (recf); utxt. verticalignment = uicontrolcontentverticalignment. center; in this way, the Center is centered. For specific results, the horizontal Center is the UITextAlignment attribute: [csharp] utxt. textAlignment = UITextAlignment. center, which can be dynamically set with enumeration, for example, [csharp] utxt. textAlignment = (UITextAlignment) Enum. par Se (typeof (UITextAlignment), attr [9]); set the text size and type: [csharp] utxt. font = UIFont. fromName (Utils. tools. getFontStyle (attr [3]), f (attr [4]); [csharp] public static string GetFontStyle (string f) {return f. replace ("_", "-");} The Font attribute is ready. I have made dynamic configuration here, so I need to turn it together. In addition, the font text features in ios (I am talking about text features) are the same as those in css, separated by-signs (not underline _), for example: [csharp] public enum FontStyle {AcademyEngravedLetPlain, AmericanTypewriter_CondensedLight, AmericanTypewriter_Light, AmericanTypewriter, AmericanTypewriter_Condensed ,... The font text above is a digress. The most common setting of UILabel is automatic line feed. The following settings must be made: [csharp] public static UILabel CreateLbl (RectangleF frame, string title, int line = 0, bool clearbgc = true) {UILabel l = new UILabel (frame); l. text = title; l. adjustsFontSizeToFitWidth = true; l. lineBreakMode = UILineBreakMode. tailTruncation; l. lines = line; if (clearbgc) l. backgroundColor = UIColor. clear; else l. backgroundColor = UIColor. red; // return l for the Test layout ;} The most important attribute is the LineBreakMode attribute. The lines attribute specifies the height of the uilabel area, which can be divided into several lines for text arrangement. The default value is 1. By the way, the programming style in the xamarin development environment is a bit like java. Except for the outermost layer, parentheses are arranged in a positive direction, and the rest are arranged in a diagonal angle, similar to javascript, so get used to it. I will not talk about color settings much. I 'd like to talk about UIColor. fromRGB method, which is literally easy to understand, is to obtain the color through three rgbvalues, such as: [csharp] public static void SetFontColor (UILabel c, string strRGB) {string [] rgb = strRGB. split (','); c. textColor = UIColor. fromRGB (FormateObject. getInt (rgb [0]), FormateObject. getInt (rgb [1]), FormateObject. getInt (rgb [2]);} will be added later

Related Article

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.