Я один класс с именем "Меню" создание UIButton:Добавить UIButton в ViewController из пользовательского класса
.h файл:
@interface Menu : NSObject
@property (strong) Forme *forme;
@property (strong) NSString *imageButtonName;
@property (strong) UIButton *button;
- (id) initWithClef:(int)clef hauteur:(int)hauteur largeur:(int)largeur posY:(int)posY posX:(int)posX alpha:(float)alpha imageButtonName:(NSString*)imageButtonName button:(UIButton*)button;
@end
.m файл:
#import "Menu.h"
@implementation Menu
@synthesize forme = _forme;
@synthesize button = _button;
@synthesize imageButtonName = _imageButtonName;
- (id) initWithClef:(int)clef hauteur:(int)hauteur largeur:(int)largeur posY:(int)posY posX:(int)posX alpha:(float)alpha imageButtonName:(NSString *)imageButtonName button:(UIButton *)button
{
if ((self = [super init]))
{
NSLog (@"test2");
self.forme =[[Forme alloc]initWithClef:clef hauteur:hauteur largeur:largeur posY:posY posX:posX alpha:alpha];
self.button = button;
[button setFrame:CGRectMake(largeur, hauteur, posX, posY)];
[button setBackgroundImage:[UIImage imageNamed:imageButtonName] forState:UIControlStateNormal];
}
return self;
}
Я хочу для автоматического отображения созданных кнопок в представлении ViewController. Кто-нибудь может мне помочь?
Спасибо! это работает. Но теперь я хочу назвать это из третьего класса. Поэтому onView не может быть «self.view». Есть ли у вас какие-либо идеи? – alex777771
Я нашел решение, спасибо! – alex777771