【问题标题】:UIlabel width set to fit on content textUIlabel 宽度设置为适合内容文本
【发布时间】:2014-09-18 03:01:36
【问题描述】:

创建了一个 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);

如何设置框架宽度大小“自动”。大小适合文本内容。

当前使用用户名作为标签并设置 label.width = 100,

label.width需要根据Label.Text里面的内容设置自动调整。

@全部 提前致谢。

【问题讨论】:

  • 发布问题后:: 我想出了答案。 lbl_Username.AttributedText.Size.Width.

标签: c# ios xamarin uilabel


【解决方案1】:
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

此链接对您有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多