Я пытаюсь сделать еще один пользовательский вид доступным в viewdidload rood VC.
MSHView *customTextView = [[MSHView alloc] initWithFrame:self.view.bounds];
customTextView.textView.text = @"abc";
[customTextView layoutSubviews];
[self.view addSubview:customTextView];
Заголовочный файл MSHView:
@property(nonatomic, strong) UITextView * textView;
@property (nonatomic, strong) UIImageView* translucentIV;
Файл реализации MSHView:
-(UIImageView*) translucentIV {
if(!_translucentIV) {
_translucentIV.frame = self.frame;
//NSLog(@"frame for translucent IV, %@", _translucentIV.frame);
_translucentIV.backgroundColor = [UIColor whiteColor];
_translucentIV.alpha = 0.5;
}
return _translucentIV;
}
-(UITextView* ) textView{
if(!_textView){
/*
float height = self.bounds.size.height - 5;
float width = self.bounds.size.width - 5;
_textView.frame = CGRectMake(5,5,width,height);
_textView.text = @"test text";
*/
NSLog(@"textview property being initialized");
}
return _textView;
}
-(void)layoutSubviews {
self.textView.frame = self.frame;
self.translucentIV.backgroundColor = [UIColor whiteColor];
self.alpha = 0.5;
NSString *abc = @"abc";
self.textView.text = [NSString stringWithFormat:@"%@",abc];
NSLog(@"layout subview being called");
}
-(void) setTextView:(UITextView *)textView {
if(textView != _textView) {
_textView = textView;
_textView.text = @"setter method called";
}
}
По-прежнему не отображается текстовое изображение из MSHView. Думаю, я неправильно делаю свойства. любая помощь или объяснение?
Заранее спасибо.
-2
CalZone
16 Мар 2013 в 01:17
1 ответ
Лучший ответ
Вы не создаете UIImageView
и UITextView
.
Попробуйте что-нибудь еще вроде:
-(UIImageView*) translucentIV {
if(!_translucentIV) {
_translucentIV = [[UIImageView alloc] initWithFrame:self.frame];
//NSLog(@"frame for translucent IV, %@", _translucentIV.frame);
_translucentIV.backgroundColor = [UIColor whiteColor];
_translucentIV.alpha = 0.5;
}
return _translucentIV;
}
-(UITextView *)textView {
if(!_textView) {
float height = self.bounds.size.height - 5;
float width = self.bounds.size.width - 5;
_textView = [[UITextView alloc] initWithFrame:CGRectMake(5,5,width,height)];
}
return _textView;
}
Вы также захотите добавить их куда-нибудь в родительский вид.
3
Cameron
16 Мар 2013 в 01:28
Внутри них, если я сделаю [self addSubView: _translucentIV]; это не работает
– CalZone
16 Мар 2013 в 01:30
1
Попробуйте [self addSubView: self.translucentIV]
– Cameron
16 Мар 2013 в 01:31
Спасибо. Это помогло. Я пошел другим путем, но вы указали мне правильное направление. Мне в основном приходилось выделять и добавлять в подпредставление.
– CalZone
16 Мар 2013 в 02:00
Похожие вопросы
Новые вопросы
ios
iOS - мобильная операционная система, работающая на Apple iPhone, iPod touch и iPad. Используйте этот тег [ios] для вопросов, связанных с программированием на платформе iOS. Используйте связанные теги [target-c] и [swift] для проблем, характерных для этих языков программирования.
_translucentIV
и_textView
. Они остаются там, будучиnil
.