kiran
kiran

Reputation: 4409

UIlabel width set to fit on content text

Created a UILabel

            lbl_Username = new UILabel {
                Text = "Username",
                Font = UIFont.FromName (DrugHub.Constants.K_HELVETIC_BOLD, KFontSize12),
            };
// Frame the label
            lbl_Username.Frame = new RectangleF (40, 20, 100, 12);
View.addSubView(lbw_Username.Frame);

How to set frame width size "auto". Size to fit on text content.

currently using Username for label and set label.width = 100,

label.width need to set automatically adjust according to content inside the Label.Text.

@All Thanks In advance.

Upvotes: 1

Views: 1169

Answers (1)

Daxesh Nagar
Daxesh Nagar

Reputation: 1415

CGSize size = [string sizeWithAttributes:
                       @{NSFontAttributeName:
                         [UIFont systemFontOfSize:17.0f]}];

Replacement for deprecated sizeWithFont: in iOS 7?

Dynamically resize label in iOS 7

Dynamically getting height of UILabel according to Text return different Value for iOS 7.0 and iOS 6.1

this link help you.

Upvotes: 1

Related Questions