iOS: creating an expandable labelHow to create a checkbox with a clickable label?UILabel is not auto-shrinking text to fit label sizeExpanding Multiline UILabelSwift Beta performance: sorting arraysAutoLayout with 2 multiline labels, compression resistance and minimum 1 line labelKeep Anchored Buttons Below Autosized LabelHow to expand - collapse UITextView in Swift?Auto-layout label and image in UITableViewCellRead/see More at the end of the labelProgramatically Created Label Within Container View Won't Expand For Text

What officially disallows US presidents from driving?

Make 2019 with single digits

How do we know that black holes are spinning?

Are there successful ways of getting out of a REVERSE MORTGAGE?

Is there any reason to concentrate on the Thunderous Smite spell after using its effects?

Planar regular languages

Can derivatives be defined as anti-integrals?

Is there a tool to measure the "maturity" of a code in Git?

Is there any way to land a rover on the Moon without using any thrusters?

Cibus sanus — healthy food?

How to count the number of occurences before a particular value in dataframe python?

How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?

How To Make Earth's Oceans as Brackish as Lyr's

Make 1998 using the least possible digits 8

What is this gigantic dish at Ben Gurion airport?

Is a suit against a University Dorm for changing policies on a whim likely to succeed (USA)?

Why the car dealer is insisting on loan instead of cash

Is low emotional intelligence associated with right-wing and prejudiced attitudes?

Are there any “Third Order” acronyms used in space exploration?

Would it be unbalanced to increase Wild Shape uses based on level?

geschafft or geschaffen? which one is past participle of schaffen?

Are space camera sensors usually round, or square?

Permutations in Disguise

Can a character with good/neutral alignment attune to a sentient object with evil alignment?



iOS: creating an expandable label


How to create a checkbox with a clickable label?UILabel is not auto-shrinking text to fit label sizeExpanding Multiline UILabelSwift Beta performance: sorting arraysAutoLayout with 2 multiline labels, compression resistance and minimum 1 line labelKeep Anchored Buttons Below Autosized LabelHow to expand - collapse UITextView in Swift?Auto-layout label and image in UITableViewCellRead/see More at the end of the labelProgramatically Created Label Within Container View Won't Expand For Text






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















I'm trying to create an expandable label that looks like the one in the picture:
enter image description here



I have two problems:



  1. How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?

  2. How do I place the More text?

Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?



Would appreciate any advice, thanks!










share|improve this question
























  • How are you going to put it back once the text label is expanded?

    – El Tomato
    Mar 28 at 12:22

















-2















I'm trying to create an expandable label that looks like the one in the picture:
enter image description here



I have two problems:



  1. How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?

  2. How do I place the More text?

Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?



Would appreciate any advice, thanks!










share|improve this question
























  • How are you going to put it back once the text label is expanded?

    – El Tomato
    Mar 28 at 12:22













-2












-2








-2








I'm trying to create an expandable label that looks like the one in the picture:
enter image description here



I have two problems:



  1. How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?

  2. How do I place the More text?

Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?



Would appreciate any advice, thanks!










share|improve this question














I'm trying to create an expandable label that looks like the one in the picture:
enter image description here



I have two problems:



  1. How do I make the label truncate the tail such that it leaves enough place for the More button/clickable text?

  2. How do I place the More text?

Maybe, I am going about it the wrong way? Instead of playing with the number of lines, should I maybe try to calculate how much text goes into one and a half line and present it only, and then when clicking More I present the whole text?



Would appreciate any advice, thanks!







ios swift text label expandable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 11:08









YotamYotam

2,9169 gold badges37 silver badges55 bronze badges




2,9169 gold badges37 silver badges55 bronze badges















  • How are you going to put it back once the text label is expanded?

    – El Tomato
    Mar 28 at 12:22

















  • How are you going to put it back once the text label is expanded?

    – El Tomato
    Mar 28 at 12:22
















How are you going to put it back once the text label is expanded?

– El Tomato
Mar 28 at 12:22





How are you going to put it back once the text label is expanded?

– El Tomato
Mar 28 at 12:22












1 Answer
1






active

oldest

votes


















1
















You can use this library to achieve your expected output.



https://github.com/apploft/ExpandableLabel



Specify the number of lines you want to display default.



expandableLabel.numberOfLines = 2


Set true if the label should be collapsed or false for expanded.



expandableLabel.collapsed = true


collapsedAttributedLink
Set the link name that is shown when collapsed.



expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")


expandedAttributedLink
Set the link name that is shown when expanded. It is optional and can be nil.



expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55396079%2fios-creating-an-expandable-label%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    You can use this library to achieve your expected output.



    https://github.com/apploft/ExpandableLabel



    Specify the number of lines you want to display default.



    expandableLabel.numberOfLines = 2


    Set true if the label should be collapsed or false for expanded.



    expandableLabel.collapsed = true


    collapsedAttributedLink
    Set the link name that is shown when collapsed.



    expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")


    expandedAttributedLink
    Set the link name that is shown when expanded. It is optional and can be nil.



    expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")





    share|improve this answer





























      1
















      You can use this library to achieve your expected output.



      https://github.com/apploft/ExpandableLabel



      Specify the number of lines you want to display default.



      expandableLabel.numberOfLines = 2


      Set true if the label should be collapsed or false for expanded.



      expandableLabel.collapsed = true


      collapsedAttributedLink
      Set the link name that is shown when collapsed.



      expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")


      expandedAttributedLink
      Set the link name that is shown when expanded. It is optional and can be nil.



      expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")





      share|improve this answer



























        1














        1










        1









        You can use this library to achieve your expected output.



        https://github.com/apploft/ExpandableLabel



        Specify the number of lines you want to display default.



        expandableLabel.numberOfLines = 2


        Set true if the label should be collapsed or false for expanded.



        expandableLabel.collapsed = true


        collapsedAttributedLink
        Set the link name that is shown when collapsed.



        expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")


        expandedAttributedLink
        Set the link name that is shown when expanded. It is optional and can be nil.



        expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")





        share|improve this answer













        You can use this library to achieve your expected output.



        https://github.com/apploft/ExpandableLabel



        Specify the number of lines you want to display default.



        expandableLabel.numberOfLines = 2


        Set true if the label should be collapsed or false for expanded.



        expandableLabel.collapsed = true


        collapsedAttributedLink
        Set the link name that is shown when collapsed.



        expandableLabel.collapsedAttributedLink = NSAttributedString(string: "More")


        expandedAttributedLink
        Set the link name that is shown when expanded. It is optional and can be nil.



        expandableLabel.expandedAttributedLink = NSAttributedString(string: "Less")






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 11:53









        AtulParmarAtulParmar

        2,2169 silver badges26 bronze badges




        2,2169 silver badges26 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55396079%2fios-creating-an-expandable-label%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript