Wrapping text on TitleLabel and DetailLabel - Material Card

79 Views Asked by At

I am using CosmicMind - Material Framework to create a Card. titleLabel and DetailLabel do not wrap to a new line.

My question is: What do I need to do to accomplish such task and is it supposed to be automatically adjusted by the framework?

This is what I have so far:

    let card = Card()
    var heartIcon = IconButton()
    heartIcon = IconButton(image: Icon.favoriteBorder, tintColor: Color.red.base)

    //Title Bar
    let toolbar = Toolbar(rightViews: [heartIcon])
    toolbar.title = cardData.cardTitleText
    toolbar.titleLabel.textAlignment = .left
    toolbar.titleLabel.numberOfLines = 0

    toolbar.detail = "Company: " + cardData.cardTitleSubtitle
    toolbar.detailLabel.font = RobotoFont.regular(with: 14)
    toolbar.detailLabel.textColor = Color.grey.base
    toolbar.detailLabel.textAlignment = .left
    toolbar.detailLabel.numberOfLines = 0

And this is my output:

enter image description here

Update: I managed to achieve what I wanted by increasing the size of the toolbar frame.

toolbar.frame = CGRect(x:0,y:0,width: view.frame.width,height: 100)

My goal was to at least show 2 lines of text.

Thanks!

1

There are 1 best solutions below

2
Razvan S. On

I have no experience with the CosmicMind framework but usually, the label.numberOfLines property defines the maximum number of lines that the label text can have. You can set it to 2 instead of 0 and it should wrap.