iphone - 带有 UIcontrols 元素的自定义 View

标签 iphone objective-c ios

我创建了一个自定义 View 类,它是 UIview 类的子类

 @interface CustomViewController : UIView

我正在使用drawRect方法来显示自定义 View 的内容

-(void) drawRect(CGRect) rect {

}

我只能在自定义 View 上显示字符串,但我想在自定义 View 上添加 UITextField 和 UILabelField 和 UIButton 我该怎么做。请帮我解决这个问题

最佳答案

您可以将控件放入自定义 View 的 init... 方法中。

编辑

- (id)initWithFrame:(CGRect)frame 
{    
    self = [super initWithFrame:frame];
    if (self) 
    {
       messageLabel.frame = CGRectMake(10, 20, innerView.frame.size.width-20, 100);
       messageLabel = [messageLabel getSize:messageText FontName:@"Helvetica" FontSize:16 label:messageLabel];
       messageLabel.textColor = [UIColor blackColor];
       messageLabel.textAlignment = UITextAlignmentCenter;
       messageLabel.backgroundColor = [UIColor clearColor];
       messageLabel.frame = CGRectMake(10, 40, innerView.frame.size.width-20,messageLabel.frame.size.height );
       [self addSubview:messageLabel];
    }
    return self;
}

关于iphone - 带有 UIcontrols 元素的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8570820/

相关文章:

ios - 解除模态呈现的 View Controller 时框架不正确

ios - 设置 UISearchBar 的搜索字段背景图像会更改填充

iphone - 对内存管理的一些理解

ios - 使用 SiriKit 开始锻炼时,Siri 始终响应 'Continue in the app'

iOS 动画——像 Siri 一样向上滚动文本

objective-c - 当我不在 dealloc 中释放它时,为什么 : @property(copy) NSString* name, 没有内存泄漏?

iphone - 设置最大和最小修剪长度 IOS

iOS Popover 在关闭后不会消失

iphone - 在不使用标签的情况下在按钮操作方法中传递参数

ios - 不使用换行符定义核心文本段落?