objective c - Set a UIView in a fixed proportional position from the Right Edge of screen iOS -


say, have uiimageview or object , set in uiview subview cgrectmake this:

uiview *headerview = [[uiview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, 30)];  uiimageview *imgview = [[uiimageview alloc]initwithframe:cgrectmake(266, 0, 30, 30)];     [imgview setimage:[uiimage imagenamed:[self.imagedickey objectatindex:section]]];     [headerview addsubview:imgview]; 

here set position of imgview cgrectmake(266, 0, 30, 30)]; , counts it's position form left x position (which 266). if want set imgview's position right side of screen? that,in different width of iphone screen shows in same ratio position. counted it's position right edge. lot in advanced.

i recommend not hard coding exact positions , instead calculating x , y. way different sized screens it's not exact position , rather it's based upon views' size.

uiview *headerview = [[uiview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, 30)];  cgfloat padding = 20;   // amount padding cgsize size = cgsizemake(30, 30);   // size of imageview cgpoint startpos = cgpointmake(headerview.frame.size.width - padding - size.width, 0);  // starting position imageview  uiimageview *imgview = [[uiimageview alloc]initwithframe:cgrectmake(startpos.x, startpos.y, size.width, size.height)]; [imgview setimage:[uiimage imagenamed:[self.imagedickey objectatindex:section]]]; [headerview addsubview:imgview]; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -