Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在iPhone应用程序中自定义许多UI按钮_Ios_Uibutton_Calculator_Iboutlet - Fatal编程技术网

Ios 在iPhone应用程序中自定义许多UI按钮

Ios 在iPhone应用程序中自定义许多UI按钮,ios,uibutton,calculator,iboutlet,Ios,Uibutton,Calculator,Iboutlet,在iPhone应用程序中,我在一个视图中有一堆UIButton(大约60个按钮)。我使用以下方法自定义按钮的外观 - (void) setButtonAttributes:(UIButton *) buttonName withTitle:(NSString *)title withImage:(NSString *) imageSuffix { NSString *unpressedName, *pressedName; pressedName = [NSString stri

在iPhone应用程序中,我在一个视图中有一堆UIButton(大约60个按钮)。我使用以下方法自定义按钮的外观

- (void) setButtonAttributes:(UIButton *) buttonName withTitle:(NSString *)title withImage:(NSString *) imageSuffix
{
    NSString *unpressedName, *pressedName;
    pressedName = [NSString stringWithFormat:@"pressed%@.png", imageSuffix];
    unpressedName = [@"un" stringByAppendingString: pressedName];
    buttonName.layer.cornerRadius = 5;
    buttonName.clipsToBounds = YES;
    [buttonName setTitle:title forState:UIControlStateNormal];
    if ([imageSuffix isEqualToString:@""] || [imageSuffix isEqualToString:@"brown"] ||  [imageSuffix isEqualToString:@"green"])
    {
    buttonName.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [buttonName setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonName setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [buttonName setBackgroundImage:[UIImage imageNamed:unpressedName] forState:UIControlStateNormal];
    [buttonName setBackgroundImage:[UIImage imageNamed:pressedName] forState:UIControlStateHighlighted];
    }
    else
    {
    [buttonName setImage:[UIImage imageNamed:unpressedName] forState:UIControlStateNormal];
    [buttonName setImage:[UIImage imageNamed:pressedName] forState:UIControlStateHighlighted];
    }
    [buttonName addTarget:self action:@selector(playClick) forControlEvents:UIControlEventTouchDown];
}

因此,我在视图的-(void)viewdiload中调用这个方法大约60次。例如:

 [self setButtonAttributes:firstButton withTitle:@"First" withImage:@"brown"]; 
 IBOutlet  UIButton *firstButton; 
一些按钮在IB中可见。但也有一些按钮在IB中不可见,因此我使用以下内容来演示它们:

secondButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
secondButton.frame = CGRectMake(64, 394, BUTTOM_WIDTH, BUTTOM_HEIGHT);
secondButton.bounds = CGRectMake(0, 0, BUTTOM_WIDTH, BUTTOM_HEIGHT);
[self setButtonAttributes:secondButton withTitle:@"Second" withImage:@"brown"];    
[secondButton addTarget:self action:@selector(someSelector) forControlEvents:UIControlEventTouchUpInside];
[somePane addSubview:secondButton];  //somePane is a scrollview.
所有这60个按钮都在视图的头文件中定义了一个IBOutlet。例如:

 [self setButtonAttributes:firstButton withTitle:@"First" withImage:@"brown"]; 
 IBOutlet  UIButton *firstButton; 

当我将我的应用程序与iPhone的计算器应用程序进行比较时,我注意到iPhone的计算器按钮比我的应用程序更快捷。所以基本上,我的问题是,与iPhone的计算器相比,我的应用程序中按钮的响应时间要慢得多。我想知道这是否与我在上面代码中解释的自定义按钮的方式有关?如果是这样的话,定制这些按钮的正确方法是什么?

您是否在没有设置单个特征的情况下测量了性能?我相信我在设置图像和其他设置(如上面的代码)后注意到了性能问题。这就是为什么我只能认为是因为这个。此外,当按下任何一个按钮时,我都无法改变幕后的情况。所以我认为我没有正确有效地设置这些设置。