coolmac
coolmac

Reputation: 1603

Why isn't a new line being created?

I'm trying to break the UILabel into 3 parts, the top line will be the Title, second line will be the artist, and the third line will be the album. Why is the UILabel not displaying it in three lines?

 var ID3 = UILabel(frame: CGRectMake(0,0,200,200))
    ID3.center = CGPointMake(160, 284)
    ID3.textAlignment = NSTextAlignment.Center
    ID3.text = (Title + "\n" + Artist + "\n" + Album)
    self.view.addSubview(ID3)

Upvotes: 0

Views: 48

Answers (1)

sloik
sloik

Reputation: 732

ID3.numberOfLines = 3

Hope that helps ;) The default value for this property is 1 and if you set it to 0 then you will have a multiline label :)

Edit: Sample playground code:

//: Playground - noun: a place where people can play

import UIKit

let Title = "Lorem ipsum title"
let Artist = "lorem ipsum artist"
let Album = "lorem ipsum album"

var ID3 = UILabel(frame: CGRectMake(0,0,200,200))
ID3.center = CGPointMake(160, 284)
ID3.textAlignment = NSTextAlignment.Center
ID3.text = (Title + "\n" + Artist + "\n" + Album)
ID3.numberOfLines = 3
ID3.backgroundColor = UIColor.redColor()

var view = UIView(frame: CGRectMake(0, 0, 500, 500))
view.backgroundColor = UIColor.whiteColor()

view.addSubview(ID3)

enter image description here

Upvotes: 1

Related Questions