ios - Xcode Obj-C - How do you change the width of a UIImageView as well as the UIImage inside of it -
i have 3 uiimageview , each contains image. have if statement when triggered should change width of image.
i have tried:
relaxedv.frame = cgrectmake(0, 53, 320, 479); relaxedv.frame = cgsizemake(0, 53, 320, 479); relaxedv.image = cgrectmake(0, 53, 320, 479); relaxedv.image = cgsizemake(0, 53, 320, 479); and few others nothing works far. how can change width? there better way using uiimageview? images solid colors have them drawn code if instruct me too
here several cases.
you may using
autolayout. in case setting frames manually discouraged, should change constraints instead. read here @ so further informationyou may use
autoresizingmask. if set adjust width superview or that, discouraged break rules. instead reconsider autoresizing mask settingsyou manually. in case, may use following code change
width:
code:
cgrect relaxedvframe = relaxedv.frame; relaxedvframe.size.width = newwidth; relaxedv.frame = relaxedvframe; you mention images solid color, recommend following approach:
+ (uiimage *)imagewithcolor:(uicolor *)color { cgrect rect = cgrectmake(0.0f, 0.0f, 1.0f, 1.0f); uigraphicsbeginimagecontext(rect.size); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, [color cgcolor]); cgcontextfillrect(context, rect); uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return image; } you may use code put solid-colored image sized uiimageview
Comments
Post a Comment