好的,所以以我几天前才真正开始学习原生iOS的事实作为开头,来自Titanium。我有动态 UI(导航元素),将根据用户是否登录来创建。在下面的代码中,我了解如何创建按钮,但我无法为按钮设置背景图像,代码提示甚至没有给我选项。如果我在将按钮分配给它的文件中设置了一个 IBOutlet .h
,那么我可以访问该setBackgroundImage
方法。.h
如果我不知道最终将拥有多少个 navButton,我无法在文件中为每个按钮设置属性?
还是我以完全错误的方式处理这个问题?我应该创建一个单独的类来处理这个吗?你可能会说我有点迷路了。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.iconArray = @[@"member-icon",@"join-icon",@"business-development-icon",@"referral-system-icon",@"apprenticeship-icon",@"links-icon",@"paydues-icon"];
//Find out how many views are in the iconArray
NSInteger numberOfViews = [self.iconArray count];
for (int i = 0; i < numberOfViews; i++) {
//create the sub view and allocate memory
UIView *navButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 102, 85)];
[self.navScroller addSubview:navButton];
}
}