Wie Sie ein UILabel als Untersicht von UIButton iOS

Möchte ich hinzufügen, dass ein UILabel innerhalb einer UIButton.
Hier ist mein code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[self addressSearch] setDelegate:self];
    [[self worldMap] setDelegate:self];

    self.boolPushButtonTapped = YES;
    self.addressSearch.barStyle = 1;

    //Create pushButton
    self.pushButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.pushButton.frame = CGRectMake(106, 436, 110, 59);

    [self.pushButton setBackgroundImage:[UIImage imageNamed:@"pushButton2.png"] forState:UIControlStateNormal];
    [self.pushButton addTarget:self action:@selector(pushButtonTapped) forControlEvents:UIControlEventTouchUpInside];


    //Label
    self.distanceLabel = [[UILabel alloc] init];

    self.distanceLabel.text = @"test";

    [self.pushButton addSubview:self.distanceLabel];


    [self.view addSubview:self.pushButton];
}

Wenn ich nicht verwenden alloc init ich eine Fehlermeldung und wenn ich den text in das label ändert sich nicht.
Fehler:

*** Assertion failure in -[NSLayoutConstraint constant], /SourceCache/Foundation/Foundation-992/Layout.subproj/NSLayoutConstraint.m:560
2012-10-01 14:01:01.889 RemindMe[1116:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)'

Möchte ich hinzufügen, dass innerhalb dieser button, denn es gibt eine animation.

Irgendwelche Vorschläge?

  • Möchten Sie den text einer Schaltfläche oder ein UILabel-Instanz innerhalb des Rahmens von einem UIButton?
  • Legen Sie ein UILabel-Instanz innerhalb der UIButton
InformationsquelleAutor Camus | 2012-10-01
Schreibe einen Kommentar