0

UIButton我在我的viewDidLoad方法中加载了一些默认值并设置了自定义项。默认加载正常。但是,UIButtons他们没有得到他们的定制。

当我将完全相同的UIButton代码放在操作按钮中以触发自定义时 - 效果很好。我在 .xib 中将按钮更改为“自定义”。

我觉得发生了一些不正常的事情,这就是为什么按钮没有随他们的模组一起启动的原因。

- (void)viewDidLoad {

    lifeTotal.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"bankKey"];
    floatTot = [[NSUserDefaults standardUserDefaults] floatForKey:@"floatKey"];
    dollaInt = [[NSUserDefaults standardUserDefaults] integerForKey:@"intKey"];
    hourlyRate.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"rateKey"];
    rate = [[NSUserDefaults standardUserDefaults] integerForKey:@"rateInt"];

    NSArray *buttons = [NSArray arrayWithObjects: self.start, self.stop, self.fbButton, self.clearLifeTotal,nil];


    for(UIButton *btn in buttons)
    {
        // Set the button Text Color
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];

        // Set default backgrond color
        [btn setBackgroundColor:[UIColor blackColor]];

        // Round button corners
        CALayer *btnLayer = [btn layer];
        [btnLayer setMasksToBounds:YES];
        [btnLayer setCornerRadius:5.0f];

        // Apply a 1 pixel, black border around Buy Button
        [btnLayer setBorderWidth:1.0f];
        [btnLayer setBorderColor:[[UIColor blackColor] CGColor]];

    }
    [super viewDidLoad];
}
4

3 回答 3

0

很抱歉,快速查看UIButton.h显示 viewDidLoad 未在 UIButton 上公开。因此,它没有被调用。

您正在寻找-(id)initWithFrame:(CGRect)frame-(id)initWithCoder:(NSCoder *)aDecoder

于 2013-09-12T20:32:07.993 回答
0

您是否尝试将 [super viewDidLoad] 放在方法的顶部,在您的代码之前?

于 2013-02-14T03:00:17.823 回答
0

尝试用这个替换你的 for 循环并检查:

    for (UIButton *btn in self.view.subviews)
    {
        if (btn == self.start || btn == self.stop || btn == self.fbButton || btn == self.clearLifeTotal)
        {
            // Set the button Text Color
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];

            // Set default backgrond color
            [btn setBackgroundColor:[UIColor blackColor]];

            // Round button corners
            CALayer *btnLayer = [btn layer];
            [btnLayer setMasksToBounds:YES];
            [btnLayer setCornerRadius:5.0f];

            // Apply a 1 pixel, black border around Buy Button
            [btnLayer setBorderWidth:1.0f];
            [btnLayer setBorderColor:[[UIColor blackColor] CGColor]];
        }
    }
于 2013-02-14T04:08:59.827 回答