How to implement the down arrow / carriage (for example, in the iOS 9 Music application) in the iOS Swift project?

I'm looking for a better way to create a down arrow (caret?) On the right side of a UILabel in a view that is centered in UINavigationItem.

enter image description here

enter image description here

All this should look like a drop-down application in the iOS 9 Music app. The label text will change at run time, and the title / label text, including the arrow, should be centered, as in this screenshot:

Screenshot of music app on iOS 9.2

I am currently adding the \u{25BE} at the end of the text as follows:

 self.lblSelectedAlbum.text = self.lblSelectedAlbum.text! + " \u{25BE}" 

But this has several negative effects:

  • It looks cluncky
  • If the label text is too long, the down arrow disappears.

Any ideas on how to implement this best? Thanks!

+6
source share
3 answers

I suggest using an external font in attribute text. One example: Awesome font at an angle down and chevron-down.

enter image description here

If you switch to text view, you can set inserts like

 myTextView.edgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)]; //Replace 10 with the actual width that will center it. 

You can also subclass UILabel to change the way it is drawn, as in this example.

+3
source

Here is the unicode: \ u {2304}

In context, it looks like this. Avoid the hassle of downloading a new font.

  let workout = NSMutableAttributedString(string: "Workout", attributes: [NSFontAttributeName: UIFont(name: "Verdana", size: 14)!]) let arrow = NSMutableAttributedString(string: "\u{2304}", attributes: [NSFontAttributeName: UIFont(name: "Verdana", size: 37)!]) let combination = NSMutableAttributedString() combination.append(workout) combination.append(arrow) sender.setAttributedTitle(combination, for: .normal) 
+2
source

In another way, the user button and setting the text that you want to set and the texts that you set for the button, click the down arrow. if you need to set the position of the button image and button name, than use the EdgesInset image and name. Hope this helps you. Thanks

0
source

All Articles