繁体   English   中英

以编程方式或使用情节提要在UIView中显示UILabel

[英]Display UILabel in UIView programatically or using Storyboard

我添加了一个UIView ,现在,我想显示一个UILabel 但是,它不会显示。 有人可以帮我吗?

- (IBAction)infoButtonClicked:(id)sender {
    myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    myView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);


    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(5, 10, self.view.frame.size.width, 100)];

    [myView addSubview:label];

    [self.view addSubview: myView];

    [UIView animateWithDuration:0.3/1.5 animations:^{
        myView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3/2 animations:^{
            myView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.3/2 animations:^{
                myView.transform = CGAffineTransformIdentity;

                label.text=@"The title";

            }];
        }];
    }];

    //The setup code to detect single touch
    UITapGestureRecognizer *singleFingerTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(oneTap:)];
    [myView addGestureRecognizer:singleFingerTap];



}

尝试这个

UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(5, 10, myView.frame.size.width, 100)];

label.text = @"sample TExt";

label.numberOfLines = 1;
label.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
label.adjustsFontSizeToFitWidth = YES;
label.adjustsLetterSpacingToFitWidth = YES;
label.minimumScaleFactor = 10.0f/12.0f;
label.clipsToBounds = YES;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.textAlignment = NSTextAlignmentLeft;

[myView addSubview:label];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM