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

时间:2016-01-08 15:57:19

标签: ios objective-c uilabel

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

#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;
}

3 个答案:

答案 0 :(得分:-1)

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

尝试在故事板或xib文件中将其扩大。

答案 1 :(得分:-1)

尝试 -

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

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

enter image description here

答案 2 :(得分:-2)

您可以使用Autolayout。在这里,我给出了2个约束 1.来自superView的顶部 2.从superview领导

现在无论你的文字是什么,都会显示.... enter image description here