Swift dynamically sets the UILabel height, swiftuilabel

Source: Internet
Author: User

Swift dynamically sets the UILabel height, swiftuilabel


Import UIKit

Class ViewController3: UIViewController {

Override func viewDidLoad (){

Super. viewDidLoad ()

Self. view. backgroundColor = UIColor. whiteColor ()

Var scrollView = UIScrollView (frame: CGRectMake (0, 0, ScreenWidth, ScreenHeight ))

Self. view. addSubview (scrollView)

Var label = UILabel (frame: CGRectMake (0, 0, ScreenWidth, 0 ))

Label. lineBreakMode = NSLineBreakMode. ByWordWrapping

Label. numberOfLines = 0

Label. text = "through the red dust, the dust of the soul, with a touch of feelings, facing the breeze, sitting at the source of the years, watching the dance steps of time, let yourself quiet in the hourglass of time, feel the breeze, quiet and beautiful. Lying in the cradle of nature, waiting in the arms of the years, depending on the gentle time, the heart walk in the light breeze, the past together into a flower of elegance, like the quiet and beautiful sky. Like the mellow beauty of LAN, because it grows in the quiet deep valley, do not compete with the group, do not envy the Prosperous Garden, guard their own piece of Pure Land, rhyme dye the spirit of the natural world. Quietly blooming, without a trace of publicity, with the faint fragrance, let people have pity and respect. It is known as the "four gentlemen" and has the virtues of "being honest. In the future, I would like to be an orchid. I don't want to be red or purple, but I just want to fall in the plain. Don't ask everyone to look back, just want to calm down in the wind. I just want to be a simple girl. In the window of the new year, you can see the flowers bloom and the clouds roll to the cloud. Spread a pen of ink, light write, the memories of the past hidden in the traces of the text, waiting silently, quietly pity. In my life, I am not the best, but I have the most sincere and kind heart. Whether it is poor or rich, ugly or beautiful, they all look at the same psychology. Don't be arrogant, don't lie, calm, and happy. With a calm mind, we treat everyone around us with an approachable attitude. Maybe, my heart is a drop of transparent water. Eye-catching, clean and plain, heart-warming, and clear. I like to lie quietly in a rocking chair, put on headphones, and immerse myself in the beautiful music melody, so that the song will take me through the realm and be like an immersive one. Will also hear the heart drunk, heartbroken, dark tears. This kind of feeling can only be possessed in "quiet". It is a matter of quality and a clear feeling. The road to life, there are a few lavender red scattered in it, drunk the mediocrity of the journey of life. After the prosperous period, there will still be a faint fragrance, a wisp of tenderness, endless aftertaste, lingering. Flowers bloom, flowers fall, it is a year, come by accident, it is inevitable, do not complain, regret, happy to face, all look down. Light, is a quiet flower in the corner. A gentle time, a light time. I am safe in the indifferent pool, a few years, smile to see the wind smoke bypassing the fingertip. I would like to fade away with the breeze, do you still stand in the same place, holding the prosperous, reluctant to give up? I really don't want to look back, look at the vulgar lingering, tears of hypocrisy. Please let me go quietly ...... In my past, I was a Qinglian from the Buddha. I fell into the dust and fell into the rain of smoke. Unable to jump out of the three realms, trapped in the five elements, just seeking to be In the reincarnation of the six realms, and then the Qinglian before the Buddha, seeing through the troubles of the earth, selfish and greedy human nature, false and sinister, away from the human kindness and resentment, clear and clear. Looking at the red clouds, the sunset is sleeping late. Don't bother. Is the age of years old, or has long been disheartened, indifferent to the red dust. There is no such thing as competition. Just want to keep a quiet, with a stable and peaceful heart, watching the time in the green onion slowly withered, in the face of the years of cangsang, all look down. Since it cannot be changed, do not try to accept it. Do not take things as happiness, do not take oneself as sorrow, constant light, suddenly open. It is a shame to see the flowers bloom before the court. Being indifferent is the highest realm of life, an attitude towards life, a virtue, a kind of conservation, a kind of grace, a brave, a power, a principle. From the depths of the soul, do not compete with the group Fang Li, if the breeze. Life is a process of blooming flowers, and it is a kind of station for the soul to meet. Only in the quiet, can you hear the voice of flowers and feel the call of the soul. In order to see the world, after the prosperous, it became a miserable environment. In the face of duckweed, I have long been used to being alone, and watching the time passes quietly. Life gives us the happiness we deserve, but it also brings many regrets and shortcomings. There is no need to complain, no need to feel inferior, light is sunny. Instead of complaining, it is better to change your attitude towards life and strengthen the transformation of the world. Learn a Q spirit and look at the other side of things from another perspective. Looking at the problem with a calm attitude, you may see unexpected scenery, and you may encounter a "Different Spring. Calm, in the event of a storm, will see the changing. Let's look at everything in the dark, and feel every detail in life with our hearts. Let the sun shine to dilute the worries of the bottom of my heart, with a touch of blue fragrance, watching the red dust past. With a smile, the sky fades in."

Label. font = UIFont. systemFontOfSize (14)

Label. textColor = UIColor. redColor ()

Var string: NSString = label. text!


Let options: NSStringDrawingOptions =. UsesLineFragmentOrigin |. UsesFontLeading

Let boundingRect = string. boundingRectWithSize (CGSizeMake (ScreenWidth, 0), options: options, attributes: [NSFontAttributeName: label. font], context: nil)


// Var size = label. text !. SizeWithAttributes ([NSFontAttributeName: label. font])

Label. frame = CGRectMake (0, 0, boundingRect. size. width, boundingRect. size. height)

ScrollView. addSubview (label)

ScrollView. contentSize = CGSizeMake (boundingRect. size. width, boundingRect. size. height)

ScrollView. backgroundColor = UIColor. cyanColor ()

Label. backgroundColor = UIColor. blackColor ()
}
Override func didReceiveMemoryWarning (){
Super. didReceiveMemoryWarning ()
}
}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.