简体   繁体   English

在iOS上,如果将Interface Builder用于UIViewController的视图,我们如何为其实现drawRect?

[英]On iOS, if we use Interface Builder for the UIViewController's view, how do we implement a drawRect for it?

If we use Interface Builder to edit the content in the view, then how do we add a drawRect to that UIView object? 如果我们使用Interface Builder编辑视图中的内容,那么如何为该UIView对象添加drawRect (Probably we want a new class FooView that subclasses UIView -- but how will the .xib content be placed on this view?) (也许我们想要一个新类FooViewUIView ,但是.xib内容将如何放置在此视图上?)

Adding "content" to the view controller's view in the xib just involves adding subviews - these are not affected by drawRect: . 在xib中向视图控制器的视图添加“内容”仅涉及添加子视图-这些不受drawRect:影响。

That said, to set a custom class as the main view property of a view controller, just select the view in the xib, go to the identity inspector, and change the class from UIView to your custom class. 也就是说,要将自定义类设置为视图控制器的主要view属性,只需在xib中选择视图,转到身份检查器,然后将类从UIView更改为自定义类。

At beginning i want to point that i have done something like this(subclassing) with UIButton and since UIButton is inherited from UIView this must be possible with UIView too. 首先,我想指出的是,我已经使用UIButton完成了类似的操作(子类化),并且由于UIButton是从UIView继承的,因此UIView也必须可行。

(after subclassing UIView) create an instance of your subclass on your view controller and add this instance to ViewController as subview. (在对UIView进行子类化之后)在视图控制器上创建子类的实例,并将该实例作为子视图添加到ViewController。 At this point you can call your specific drawRect: method, which you have declared on your subclass 此时,您可以调用特定的drawRect:方法,该方法已在子类上声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何使用干净的面板(没有Interface Builder文件)创建iOS项目? - How do we create an iOS project with a clean slate (with no Interface Builder files)? 我们可以/如何使用iOS语音引擎? - Can we / how do we use the iOS speech engine? 界面生成器中的UIViewController的视图大小将被忽略 - UIViewController's view size from Interface Builder is ignored 我们如何决定使用 UICollectionViewController 还是 UIViewController? - How can we decide to use UICollectionViewController or UIViewController? iOS在界面生成器中使用继承的View - IOS use inherited View inside interface builder 我们如何将运球时看到的出色动画实现到ios应用程序? - How do we implement great animations we see on dribbble to an ios app? 如何在 iOS Interface Builder 的子文件夹中使用图像 - How to use images in subfolders in iOS Interface Builder iOS:如何识别我们从Parent UIViewController中的子UIViewController回来了? - iOS: How to Recognize that We Got Back from a Child UIViewController within the Parent UIViewController? 我们可以修改iOS中的UIViewController属性吗? - Can we modify the UIViewController property in iOS? iOS在视图的绘图中设置文本颜色 - iOS set text color in a view's drawrect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM