ios - How can i make clickable uiimage? -
i have 1 menubar uiimage. want make 5 menu on menubar clickable , link view. can tell me way can that? found people using uibutton on uiimage, fine me , how can separate menu bar 5 pieces.
thanks both rmaddy , brent royal-gordon
i decided use uiimage menubar background , add uibutton on it. try thing this:
nsurl *url = [nsurl fileurlwithpath:[[nsbundle mainbundle] pathforresource:@"movie" oftype:@"mp4"]]; mpmovieplayercontroller *movieplayer = [[mpmovieplayercontroller alloc] initwithcontenturl:url]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(movieplaybackdidfinish:) name:mpmovieplayerplaybackdidfinishnotification object:movieplayer]; movieplayer.controlstyle = mpmoviecontrolstylenone; movieplayer.repeatmode = mpmovierepeatmodeone; movieplayer.shouldautoplay = yes; movieplayer.scalingmode = mpmoviescalingmodefill; [movieplayer.view setframe:cgrectmake(0,0,1330,320)]; [scrollview setbackgroundcolor:[uicolor blackcolor]]; [scrollview setcontentsize:cgsizemake(1330,320)]; [scrollview setscrollenabled: yes]; [scrollview setshowshorizontalscrollindicator:no]; [scrollview setshowsverticalscrollindicator:no]; [scrollview addsubview:movieplayer.view]; [self.view addsubview:scrollview]; uiimageview *imageview = [[uiimageview alloc] initwithframe:image.frame]; uiimage *menubar = [uiimage imagenamed:@"bg.jpg"]; imageview = [[uiimageview alloc] initwithimage:menubar]; imageview.contentmode = uiviewcontentmodescaletofill; imageview.frame = cgrectmake(0, 258, imageview.frame.size.width, 25); [self.view addsubview:imageview]; [imageview setuserinteractionenabled:yes]; uibutton *btn = [uibutton buttonwithtype:uibuttontypecustom]; [btn setframe:cgrectmake(0,258,30,25)]; [btn addtarget:self action:@selector(buttonpress:) forcontrolevents:uicontroleventtouchupinside]; [btn settitle:@"home" forstate:uicontrolstatenormal]; [imageview addsubview:btn];
but button not visible on screen when run on simulator. did wrong?
using gesture recognizer bad idea because:
- it forces interpret touch areas each submenu yourself.
- it's opaque voiceover.
- it doesn't show highlight when user touches button. these sorts of highlights user understand user interface doing, they're valuable.
what should split single image 5 in graphics tool photoshop, , make each of these slices image
of uibutton
. you'll need design highlighted states these images (shown when 1 of them held down), should doing anyway.
if must slice image in code, can using uigraphicsbeginimagecontextwithoptions(size, no, 0.0)
, drawing big image using drawatpoint:
appropriate offset slice want, 99.99999% of time, it'll make more sense slice images once on big, beefy, wall-plug-powered mac every time app runs on tiny, slow, battery-powered ios device.
Comments
Post a Comment