可可触摸按钮中的多行文本?

发布于 2024-11-08 15:08:27 字数 260 浏览 0 评论 0原文

以下代码不显示多行文本

UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];

The following code don't show up multiline text

UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
viewedYou.frame = CGRectMake(0.0,0.0,61,30);
[viewedYou setTitle:@"Viewed\nYou" forState:UIControlStateNormal];
[self.view addSubview:viewedYou];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自此以后,行同陌路 2024-11-15 15:08:27

viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;

do

viewedYou.titleLabel.numberOfLines = 0;
viewedYou.titleLabel.lineBreakMode = UILineBreakModeWordWrap;
要走干脆点 2024-11-15 15:08:27

重复问题:UIButton:多行文本
但就你而言:

    UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
    viewedYou.frame = CGRectMake(0.0,0.0,61,30);

UILabel* viewedYouLabel = [[UILabel alloc] initWithFrame: viewedYou.bounds];
    viewedYouLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    viewedYouLabel.textAlignment = UITextAlignmentCenter;
    viewedYouLabel.frame = CGRectMake(0.0,0.0,61,30);
    viewedYouLabel.numberOfLines =2;
    viewedYouLabel.text = @"Viewed\nYou";
    [viewedYou addSubview: viewedYouLabel];

    [self.view addSubview:viewedYou];

Duplicate question: UIButton : Multiline text .
But in your case:

    UIButton * viewedYou = [UIButton buttonWithType: UIButtonTypeCustom];
    viewedYou.frame = CGRectMake(0.0,0.0,61,30);

UILabel* viewedYouLabel = [[UILabel alloc] initWithFrame: viewedYou.bounds];
    viewedYouLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    viewedYouLabel.textAlignment = UITextAlignmentCenter;
    viewedYouLabel.frame = CGRectMake(0.0,0.0,61,30);
    viewedYouLabel.numberOfLines =2;
    viewedYouLabel.text = @"Viewed\nYou";
    [viewedYou addSubview: viewedYouLabel];

    [self.view addSubview:viewedYou];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文