Swift dynamically sets the height of the Uilabel

Source: Internet
Author: User


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 chaos of the red dust, the soul of the dust, with a touch of light feelings, Qingxin breeze, sitting in the source of the years, watching the dance of time dancing, Let yourself quiet in the time of the hourglass, feel the light as the breeze, static if the blue of the beautiful. Supine in the cradle of nature, pillow the arms of the years, according to the time of the gentle, the heart walks in a faint breeze, the past condensed into a flower elegant, like empty valley orchid static beauty. Like Lan's mellow, because it grows in the quiet valley, not with the Zhengyan, do not envy the bustling garden, guarding their own piece of Pure land, rhyme and nature of the aura of the world. Quietly blooming, without a hint of publicity, exudes a ruoyouruowu of light incense, let the hearts of love and admiration. With the "Four great gentlemen", said, "Loh quality orchid Heart" virtue. The afterlife is willing to do orchid one, do not seek rounds, just want to open in plain. Do not ask everyone to review, just want in quiet with the wind indifferent. Just want to do a Susan shallow woman, according to the window of fleeting time, see flowers Blossom, Cloud Cirrus Shu, light if breeze, static as blue. Shop a note of ink, light pen, write, will have the memory of the words in the traces, silently waiting, quietly and Benjamin. Life, I am not the best, but I have a most sincere, kind heart. Both poverty and wealth, ugliness and beauty, are treated with the same mentality. Not arrogant not dry, not pit not cheat, calm, pleasant. With a poised heart, with an approachable attitude towards everyone around him. Perhaps, my heart is a drop of transparent drops. Eyes, clean dull, into the heart, gentle qingxin. Like a person quietly lying in a rocking chair, put on headphones, intoxicated in the music beautiful melody, let the song Take me through the realm, imitation if immersive. will also hear the enchanted, broken Heart, tears in the dark. This feeling, can only in "static" in order to have, a exquisitely carved heart, in the feelings of the inside. The road of life, there are several incense in the red and red scattered in which, the point of intoxication of life journey of mediocrity. After the prosperous, insipid, there is still a hint of lingering incense, a wisp of tenderness, memorable, lingering endlessly. Flowers, flowers, are years, to be accidental, to be inevitable, no need to complain, regret, gladly face, to see everything is light. Light, is open in the corner of a quiet floret. The years are gentle and the time is clear. I am indifferent to Enron, the number of fleeting, laughing at the wind around the fingertips of smoke. I would like to go with the wind, you are still standing in situ, holding a prosperous, nostalgia? I really do not want to look back, more than a glimpse of the vulgar lingering, tears of hypocrisy. Please let me go quietly .... Past life, I was a Buddha before a lotus, only because of the lust for the red dust, fall into the dirt, contaminated with a rain sorrow cotton. Can not jump out of the three bounded, trapped in the five elements, only in the reincarnation, and then do the Buddha before the Qinglian, see through the Earth's turmoil, human selfishness and greed, false and sinister, away from the human grievances, clear and bright. Look at the rosy, evening melt sunset mu sleep. Stride, not tired not bored. Is the years old to go, or is already disheartened, indifferent mortals. Without the exceedingly sentimental of the sentiment, no longer have the competitive germination. Just want to keep a quiet, with a stable and peaceful heart, look at the time verdant slowly withered, facing the years of the pale Mulberry, everything is light. If you can't change it, try to accept it. Do not take things happy, not to own sorrow, constant indifferent, enlightened. Look at the court before the flowers fall, chongrubujing. Indifferent, is the highest state of life, is the attitude towards life, is a virtue, a kind of self-restraint, a kind of demeanor, a kind of bravery, a force, a principle. From the depths of the soul, do not compete with the Shu Li, light if the breeze. Life is a flower of the process, is the heart of the Inn. Only in the quiet, can hear the sound of flowers, the heart of the deep call. In order to see the earthly, prosperous after the depression of the remnant. Facing the floating, I have been accustomed to alone to endure loneliness, watching the time wasted in the fleeting silent. Life gives us the happiness we deserve, but also brings many regrets and shortcomings. Do not complain, do not feel inferior, see light is sunny. Instead of complaining, change your attitude to life and strengthen the transformation of your self-world. Learn some q spirit, change the angle, you can see the other side of things. Take a calm attitude to look at the problem, you may see an unexpected scenery, with the "steady another spring" met. Calm, in distress, will see the Paradox Cloud deepness changeable. With indifferent mentality to see the world of mortals, with the soul to feel every detail of life. Let the sunshine to dilute the worries of the heart, with a touch of light orchid, watching the red dust past. Smile, in the wind light cloud light day floating shallow. "

Label.font = uifont.systemfontofsize (+)

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 NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift dynamically sets the height of the Uilabel

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.