Tôi đã tạo UICollectionView trong trình tạo giao diện. Tôi đã tham chiếu nó vớiLàm cách nào để thay đổi kích thước của UICollectionView?
@property (strong, nonatomic) IBOutlet UICollectionView *contactList;
trong tệp .h và @synthesize contactList của tôi; trong tệp .m của tôi.
tôi cố gắng thực hiện một cách bố trí hơi khác nhau trong bức chân dung và phong cảnh sử dụng đoạn mã sau:
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout*)contactList.collectionViewLayout;
flow.sectionInset = UIEdgeInsetsMake(48, 80, 48, 0);
flow.minimumLineSpacing = 80;
} else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
UICollectionViewFlowLayout *flow = (UICollectionViewFlowLayout*)contactList.collectionViewLayout;
flow.sectionInset = UIEdgeInsetsMake(48, 64, 48, 0);
flow.minimumLineSpacing = 64;
}
}
này hoạt động prefectly, nhưng tôi cũng muốn thay đổi kích thước (trong cảnh quan tôi có một lưới 2 * 3 mỗi trang và theo chiều dọc, đó là lưới 3 * 2). Tôi đã thử đặt kích thước như sau:
CGRect frame = [contactList frame];
frame.size.width = 960;
[contactList setFrame:frame];
Nhưng nó sẽ không cập nhật. Không có lỗi, nhưng chế độ xem không được cập nhật. Nó chỉ ở cùng kích thước như trước. Tôi phải làm gì để cập nhật chế độ xem?
Bạn có thể thử sử dụng 'self.contactList' không? – Amar
@amar Nó vẫn không cập nhật. – Kevin
bạn đã thử tự động đặt kích thước bằng spring-struts/autolayout chưa? –