我正在使用this control(RDVCalendarView),我想稍微自定义它。我想改变日历的高度,所以它不是整个控制器的高度,而是更小。所以在loadView
我将代码更改为:
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
applicationFrame.size.height = 200;
_calendarView = [[RDVCalendarView alloc] initWithFrame:applicationFrame];
[_calendarView setAutoresizingMask:UIViewAutoresizingNone];
[_calendarView setSeparatorStyle:RDVCalendarViewDayCellSeparatorTypeHorizontal];
[_calendarView setBackgroundColor:[UIColor whiteColor]];
[_calendarView setDelegate:self];
self.view = _calendarView;
在initWithFrame
的整个RDVCalendarView
方法中,我设置了正确的高度大小。但在viewWillAppear
之后,layoutSubviews
号召唤并且身高为504。我不知道会发生什么,但看起来高度是自动调节到控制器的高度。我只是不知道它可能在哪里。谢谢你的帮助
答案 0 :(得分:1)
通常你不直接设置UIViewController主视图的框架,参见https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/AdoptingaFull-ScreenLayout/AdoptingaFull-ScreenLayout.html
相反,您只需将要调整大小的视图作为子视图添加到视图控制器的根视图中。为此,只需将方法从loadView
更改为viewDidLoad
即可。此时,系统已为您创建了默认的UIView,并将其分配给视图控制器的view
属性。
将您的代码更改为:
- (void)viewDidLoad {
CGRect calendarFrame = self.view.frame;
calendarFrame.size.height = 200;
_calendarView = [[RDVCalendarView alloc] initWithFrame:calendarFrame];
[_calendarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[_calendarView setSeparatorStyle:RDVCalendarViewDayCellSeparatorTypeHorizontal];
[_calendarView setBackgroundColor:[UIColor whiteColor]];
[_calendarView setDelegate:self];
[self.view addSubview:_calendarView];
}
这应该可以解决问题。