UIView缺少背景
我的应用程序的结构如下所示:
UIViewController1
- UIViewController2
- Add UIView programmatically
UIViewController1包含UIViewController2,并且使用以下代码将一些UIView(从Xib载入)添加到UIViewController2:
SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject]; [self.view addSubview:b]; //- set Frame before or after addSubView, there is no difference CGRect frame = b.frame; frame.origin.x = 0; frame.origin.y = 0; b.frame = frame;
原来的UIView看起来像这样:
添加到UIViewController后,它看起来像这样:
使用下面的代码,当我将UIView的宽度和高度分配为主视图的宽度和高度的一部分时,它看起来不错
SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject]; [self.view addSubview:b]; CGRect frame = b.frame; frame.origin.x = 0; frame.origin.y = 0; //------- Assign the Width and Height Value //------------------------------------------- frame.size.width = CGRectGetWidth(self.view.bounds) / 3; frame.size.height = CGRectGetHeight(self.view.bounds) / 3; b.frame = frame;
看来要添加viewController
直接作为子视图,而不是你应该添加view
中viewController
作为子视图。
SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject];
[self.view addSubview:b.view];
链接地址: http://www.djcxy.com/p/74275.html
上一篇: UIView missing background
下一篇: UIScrollView cannot display image either in Portrait or Landscape mode