ios - How to center multiple images in scrollview in Xcode/Swift -
i trying horizontally center 30 images in scrollview. best approach so? thanks.
edit: programmatically able create images, david cao, still having issue of not centering. thanks.
if they're same image, why not programmatically? make loop , iterate through bounds.
nsinteger numwidth = 3; nsinteger numheight = 10; cgfloat border = 8; cgfloat width = (self.scrollview.frame.size.width - (numwidth + 1) * border)/3; (nsinteger = 0; < numwidth; ++i) { (nsinteger j = 0; j < numheight; ++j) { uiimageview *imageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"imagenamehere"]]; imageview.frame = cgrectmake(border + width*i, border + width*j, width, width); [self.scrollview addsubview:imageview]; } } [self.scrollview setcontentsize:cgsizemake(self.scrollview.frame.size.width, (border + width)*numheight + border];
Comments
Post a Comment