Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 114

Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
04/18/13 01:51 PM (12 years ago)

Rounding all four corners of menu list (bump)

https://www.buzztouch.com/forum/thread.php?tid=51E205E4A317965A563DF06&currentPage=1 This post led me to a little procrastination. So I did a little research for an hour and came up with this fix for it. I've bumped it because it has been asked so many times. It requires a little mod to two files. This has been tested with the simple menu plugin, I think there are a few plugins taht utilise this code so check to make sure it works. Remember if you mess up you can always just copy the code back in from another project. //position is important to maintain rounded corners if this is a "round" table. if(isRoundTable == FALSE){ bgView.position = CustomCellBackgroundViewPositionMiddle; }else{ if(theIndexPath.row == 0){ if(numRows == 1){ bgView.position = CustomCellBackgroundViewPositionSingle; }else{ bgView.position = CustomCellBackgroundViewPositionTop; } }else if(theIndexPath.row == numRows - 1){ bgView.position = CustomCellBackgroundViewPositionBottom; }else{ bgView.position = CustomCellBackgroundViewPositionMiddle; } } Then in theBT_cell_background view.m replace the whole -(void)drawRect:(CGRect)rect with the code below - (void)drawRect:(CGRect)rect { // Drawing code CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(c, [fillColor CGColor]); CGContextSetStrokeColorWithColor(c, [borderColor CGColor]); if (position == CustomCellBackgroundViewPositionTop) { CGContextFillRect(c, CGRectMake(0.0f, rect.size.height - 10.0f, rect.size.width, 10.0f)); CGContextBeginPath(c); CGContextMoveToPoint(c, 0.0f, rect.size.height - 10.0f); CGContextAddLineToPoint(c, 0.0f, rect.size.height); CGContextAddLineToPoint(c, rect.size.width, rect.size.height); CGContextAddLineToPoint(c, rect.size.width, rect.size.height - 10.0f); CGContextStrokePath(c); CGContextClipToRect(c, CGRectMake(0.0f, 0.0f, rect.size.width, rect.size.height - 10.0f)); } else if (position == CustomCellBackgroundViewPositionBottom) { CGContextFillRect(c, CGRectMake(0.0f, 0.0f, rect.size.width, 10.0f)); CGContextBeginPath(c); CGContextMoveToPoint(c, 0.0f, 10.0f); CGContextAddLineToPoint(c, 0.0f, 0.0f); CGContextStrokePath(c); CGContextBeginPath(c); CGContextMoveToPoint(c, rect.size.width, 0.0f); CGContextAddLineToPoint(c, rect.size.width, 10.0f); CGContextStrokePath(c); CGContextClipToRect(c, CGRectMake(0.0f, 10.0f, rect.size.width, rect.size.height)); } else if (position == CustomCellBackgroundViewPositionSingle) { CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ; CGFloat miny = CGRectGetMinY(rect) , midy = CGRectGetMidY(rect) , maxy = CGRectGetMaxY(rect) ; minx = minx + 1; miny = miny + 1; maxx = maxx - 1; maxy = maxy - 1; CGContextMoveToPoint(c, minx, midy); CGContextAddArcToPoint(c, minx, miny, midx, miny, 10); CGContextAddArcToPoint(c, maxx, miny, maxx, midy, 10); CGContextAddArcToPoint(c, maxx, maxy, midx, maxy, 10); CGContextAddArcToPoint(c, minx, maxy, minx, midy, 10); // Close the path CGContextClosePath(c); // Fill & stroke the path CGContextDrawPath(c, kCGPathFillStroke); return; } else if (position == CustomCellBackgroundViewPositionMiddle) { CGContextFillRect(c, rect); CGContextBeginPath(c); CGContextMoveToPoint(c, 0.0f, 0.0f); CGContextAddLineToPoint(c, 0.0f, rect.size.height); CGContextAddLineToPoint(c, rect.size.width, rect.size.height); CGContextAddLineToPoint(c, rect.size.width, 0.0f); CGContextStrokePath(c); return; // no need to bother drawing rounded corners, so we return } // At this point the clip rect is set to only draw the appropriate // // corners, so we fill and stroke a rounded rect taking the entire rect CGContextBeginPath(c); addRoundedRectToPath(c, rect, 10.0f, 10.0f); CGContextFillPath(c); CGContextSetLineWidth(c, 1); CGContextBeginPath(c); addRoundedRectToPath(c, rect, 10.0f, 10.0f); CGContextStrokePath(c); } How easy was that, that question has been asked 100 times on these forums. A bit of welcome procrastination
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
04/19/13 02:13 AM (12 years ago)
Thanks @Kittsy!!
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/19/13 05:46 AM (12 years ago)
Great share. I usually think if you just want a single menu option on a screen, why not just a button? But there's always a reason/need and as you prove yet again - there's always a way too! Thanks.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
04/19/13 06:11 AM (12 years ago)
Yeah but for people with no coding and want a nice looking button with a header image. the simple button menu can't do it because its a square and won't centre unless its massive.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.