IOS dynamically defines the height and iostextview for TextView based on the text content.

Source: Internet
Author: User

IOS dynamically defines the height and iostextview for TextView based on the text content.

Solution:

1. Define a textview and set the constraints of the textview in storyboard.

2. Define the height constraint in the header file: (drag it directly)

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textviewHeightConstraint;
3. After the content is loaded for textview in the implementation file, obtain the text height and assign the value to the constraint:

    CGSize sizeThatShouldFitTheContent = [self.shippingAddressTextView sizeThatFits:self.shippingAddressTextView.frame.size];    self.textviewHeightConstraint.constant = sizeThatShouldFitTheContent.height;

Reference link:

Http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content/2487402#2487402


How does android change the height of text view in code? text view is laid out in xml

Activity Definition
Private TextView TV;
In the onCreate function of the Activity
TV = (TextView) findViewById (R. id. TextView01)
Here, R. id. TextView01 is defined in xml
LayoutParams p = TV. getLayoutParams ();
P. height = 100;
TV. setLayoutParams (p );

Android development: how to set the text and background colors of textView statically and dynamically? Beginners do not know what to fill in details

Static is to fill in the attributes in the visualized Graphical Layout.
TextView1.TextColor (text color)
TextView1.Background (background color)
In @ android, all defined color values are automatically displayed.
For example, @ android: color/holo_blue_bright
Dynamic is set color in the program
Import android. graphics. Color;

TextView1.setTextColor (Color. RED );
TextView1.setBackgroundColor (Color. RED );

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.