3

I am a IOS learner. I was doing a sample project, in which i require "More" and "Less" text indicators in a UILabel for which i have added a SingleTapGestureRecognizer to expand and contract based on the text content.The text content comes from API and is dynamic.

Required output

Required output

Here i have attached the screen shot of my required output.(The screen shots are from android).

Also i resize the UILabel programmatically except the constraints(No Auto layout). the code use for tap gesture is

In viewDidLoad()

let singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: "singleTapped")
        singleTapGestureRecognizer.numberOfTapsRequired = 1
        singleTapGestureRecognizer.enabled = true
        singleTapGestureRecognizer.cancelsTouchesInView = false

        lblAmneties.addGestureRecognizer(singleTapGestureRecognizer)

the method is

var amnetiesClicked = false
func singleTapped()
{
    if(amnetiesClicked == false) { amnetiesClicked = true }
    else { amnetiesClicked = false }
    if(amnetiesClicked == true)
    {
        Amneties.sizeToFit()
        self.display()
    }
    else
    {
        if(self.Amneties.frame.size.height > 70 )
        {
            self.Amneties.frame.size.height = 70
            self.display()
        }
    }
}

Here display() is the method where i align all the contents of the view programmatically.

I have no idea on how to do it. I use xcode 7.1.1 Swift 2.0

Kautham Krishna
  • 967
  • 1
  • 14
  • 33
  • see this http://stackoverflow.com/questions/32309247/add-read-more-to-the-end-of-uilabel – Anbu.Karthik Mar 11 '16 at 06:52
  • Thanks for your Response. But i don't know objective c and i am unable to convert the code to swift. Could you please give me the swift version of the code ? – Kautham Krishna Mar 11 '16 at 07:08

1 Answers1

0

I used TTTAttributed Label to do that https://github.com/TTTAttributedLabel/TTTAttributedLabel It has a predefined method to do that.

Kautham Krishna
  • 967
  • 1
  • 14
  • 33