Vote count:
0
been trying to figure this out for a while. I'm tapping on the CNPPopupController and I'm trying to add a UIScrollView into the UIView.
In the scroll view I will be adding the content, I have tried so far but the content does not seem to be appearing in the UIScrollView. I am not sure what I'm doing wrongly, can anyone please guide me?
//The content view that will house labels and a UIScrollView
self.contentView = [[UIView alloc] init];
[self.contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
self.contentView.clipsToBounds = YES;
self.contentView.backgroundColor = self.theme.backgroundColor;
self.contentView.layer.cornerRadius = self.theme.popupStyle == CNPPopupStyleCentered ? self.theme.cornerRadius : 0.0f;
[self.maskView addSubview:self.contentView];//The UI ScrollView
self.scrollView = [[UIScrollView alloc] init];
//self.scrollView.backgroundColor= self.theme.backgroundColor;
self.scrollView.frame = CGRectMake(50, 50, 200, 100);
self.scrollView.layer.cornerRadius = self.theme.popupStyle == CNPPopupStyleCentered ? self.theme.cornerRadius : 0.0f;
self.scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
self.scrollView.scrollEnabled = YES;
if (self.popupTitle) {
UILabel *title = [self multilineLabelWithAttributedString:self.popupTitle];
[self.contentView addSubview:title];
}
//Adding items in the UISCrollView
if (self.contents) {
for (NSObject *content in self.contents) {
if ([content isKindOfClass:[NSAttributedString class]]) {
UILabel *label = [self multilineLabelWithAttributedString:(NSAttributedString *)content];
[label sizeToFit];
CGSize scrollViewContentSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height+500);
[self.scrollView setContentSize:scrollViewContentSize];
[self.scrollView addSubview:label];
}
else if ([content isKindOfClass:[UIImage class]]) {
UIImageView *imageView = [self centeredImageViewForImage:(UIImage *)content];
[imageView sizeToFit];
CGSize scrollViewContentSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height+500);
[self.scrollView setContentSize:scrollViewContentSize];
[self.scrollView addSubview:imageView];
[self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:imageView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
}
}
[self.contentView addSubview:self.scrollView];
}
asked 22 secs ago
UILabel/Content not appearing in UIScrollView
Aucun commentaire:
Enregistrer un commentaire