iOS 标签只显示“...”而不是预期的文本

iOS Labels only showing '...' instead of expected text

我正在尝试在标签中显示设备的偏航俯仰和滚动。我似乎无法获得要显示的值,它只在数字应该显示的位置显示“...”。这是我的代码,非常感谢任何帮助。

#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>

@interface ViewController (){

}
@property (strong, nonatomic) CMMotionManager *motionManager;
@end

@implementation ViewController

@synthesize motionManager;
@synthesize roll;
@synthesize pitch;
@synthesize yaw;

@synthesize xLabel;
@synthesize yLabel;
@synthesize zLabel;

- (void)viewDidLoad {
    [super viewDidLoad];
    /** Do any additional setup after loading the view, typically from a nib.
    UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
    accelerometer.updateInterval = 1.0f/60.0f;
    accelerometer.delegate = self;
     **/
    //motionManager = [[CMMotionManager alloc] init];
    //motionManager.deviceMotionUpdateInterval = 1.0 / 60.0;

    motionManager = [[CMMotionManager alloc] init];
    NSTimer *timer;
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(doGyroUpdate) userInfo:nil repeats:YES];

    //CMDeviceMotion *deviceMotion = motionManager.deviceMotion;
    //CMAttitude *attitude = deviceMotion.attitude;

    [motionManager startDeviceMotionUpdates];
}

-(void)doGyroUpdate
{
    double x = motionManager.deviceMotion.attitude.roll*180/M_PI;
    double y = motionManager.deviceMotion.attitude.pitch*180/M_PI;
    double z = motionManager.deviceMotion.attitude.yaw*180/M_PI;

    NSString *myString = [NSString stringWithFormat:@"%g", x];
    xLabel.text = myString;
    myString = [NSString stringWithFormat:@"%f", y];
    yLabel.text = myString;
    myString = [NSString stringWithFormat:@"%f", z];
    zLabel.text = myString;
}

... 表示您用于显示文本的 UILabel 没有达到应有的宽度。

尝试在您的故事板或 xib 文件中使其更宽。

尝试 -

label.numberOfLines = 1;
label.minimumFontSize = 6;
label.adjustsFontSizeToFitWidth = YES;

或者您可以通过故事板尝试(自动收缩选项)-

您可以为此使用自动版式。在这里我给了 2 个约束 1. superView 顶部 2. 从 superview 开始

现在无论您的文本是什么,它都将在没有....的情况下显示。