사용자 정의 뷰 ganttChartView를 작성하고 스토리 보드에서 추가했습니다. 이제 ganttChartView에서 나는 timeLine을 나타내고 프로그램 적으로 추가 된 UICollection View를 가지고있다. 방향 변경시 하위 뷰 (UICollectionView) 자동 렌더링
// Initialize GanttChat View from Interface Builder or Storyboard File
-(id)initWithCoder:(NSCoder *)aDecoder
{
self= [super initWithCoder:aDecoder];
if (self) {
self.timeLineHeight =KMinTimeLineCellHeight;
self.timeLineCellWidth=kMinTimeLineCellWidth;
self.backgroundColor = [UIColor redColor];
self.autoresizesSubviews = YES;
}
return self;
}
-(void)reloadTimelineView
{
[self initializeTimeLineView];
[self.timeLineCollectionView reloadData];
}
-(void) initializeTimeLineView
{
// Initialization of StartDate End Date and DateMode Property
[self initializeTimeLineDates];
// Creating Layout for Collection view
UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
CGSize cellSize =CGSizeMake(self.timeLineCellWidth, self.timeLineHeight) ;
flowLayout.itemSize = cellSize ;
flowLayout.minimumInteritemSpacing= 1.0f;
flowLayout.minimumLineSpacing=5.0f;
CGRect timeLineFrame =CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, self.timeLineHeight);
// Initialization of CollectionView for TimeLine
self.timeLineCollectionView = [[UICollectionView alloc] initWithFrame:timeLineFrame collectionViewLayout:flowLayout];
[self.timeLineCollectionView registerClass:[A3TimeLineCollectionViewCell class] forCellWithReuseIdentifier:timeLineCell_ID];
self.timeLineCollectionView.backgroundColor = self.timeLineBackgroundColor;
// Initialization of CollectionView DataSource and Delegate with Start Date and End date and DateMode
self.timeLineDataSource = [[A3GanttChartTimeLineDelegate alloc] initWithDate:self.startDate andDate:self.endDate withMode:self.dateType];
self.timeLineDataSource.gantChartView = self;
self.timeLineDataSource.timeLineEachCellColor = self.timeLineEachCellColor;
self.timeLineCollectionView.delegate=self.timeLineDataSource;
self.timeLineCollectionView.dataSource=self.timeLineDataSource;
[self addSubview:self.timeLineCollectionView];
}
이제 스토리 보드에서 나는 장애인 자동 레이아웃 옵션을 가지고이 방향 변경 후 크기를 조정할 수 있도록 ganttChartView의 크기 경위에서 나는 상단과 왼쪽 모서리에 고정 설정했습니다.
이익 모드
풍경 모드 또한 방향 변경 후 크기를 조정하기 위해 고정 오른쪽 모서리를 설정해야
답장을 보내 주셔서 감사합니다. 그러나 제대로 작동하지 않았습니다. 이 문제를 해결하기 위해 NSLayoutConstraint를 프로그램 적으로 사용하는 방법이 있습니까? –