TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Designing for iOS: Taming UIButton

59 点作者 kaishin超过 12 年前

8 条评论

andymatuschak超过 12 年前
It's really worth noting that there are substantial performance ramifications to your choice here, in terms of CPU time for generation, memory usage, I/O, and GPU time for rendering.<p>The resizable image background technique will be the fastest option (provided you don't need to programmatically tweak the appearance). Next would be the full-sized background (which needlessly wastes memory). Then the CG-based approach, which could actually perform better than the full-sized background if you had generated a resizable image—the technique presented here needlessly wastes memory and CPU time by generating a full-width image. But it will still perform worse in basically all cases than the resizable-image-from-disk technique, so you would only want to do that if the parameters need to be tweaked at runtime.<p>The CAGradientLayer-based approach (as written) is a very poor idea unless you need the animated transitions because it requires extremely expensive off-screen drawing passes due to the masking. If your situation permits you to use "overdrawn" masking (as I discussed in WWDC 2012's "Polishing Your Rotation Animations"), this would actually perform quite well—less memory consumption than all the other options; small rendering cost each frame. See also WWDC 2011's "Understanding UIKit Rendering" for more on graphics performance with UIKit.<p>I guess it's also worth noting that the cost of masking CALayers with a borderRadius is much lower in iOS 6 than iOS 5, but don't go nuts: it's still way higher than all these other options.
评论 #4646368 未加载
评论 #4646414 未加载
评论 #4645696 未加载
评论 #4646373 未加载
coob超过 12 年前
Drawing controls in code, unless you gain something other than the space saved for bitmaps, is a waste of time and energy. You gain nothing by drawing the gradients for buttons in code.<p>If it all ends up in that format anyway, you might as well do what Apple does 95% of the time: just use bitmaps. In mobile, saving cycles is more important than saving storage.
评论 #4645407 未加载
评论 #4645396 未加载
评论 #4645426 未加载
aaronbrethorst超过 12 年前
<p><pre><code> A recently introduced second option consists in using a resizable image as a button background after having set its resizable and non-resizable areas in code. Start by making a pill-shaped background image in your graphic editor. </code></pre> Not accurate. -[UIImage stretchableImageWithLeftCapWidth:topCapHeight] has been around since the first public SDK release. Although, I must say the -resizableImageWithCapInsets: methods added in iOS 5 and 6 are far more powerful.<p>Also, here are a bunch of UIButton subclasses that I think are pretty neat that demonstrate some of the techniques described in the article, plus others:<p><a href="http://www.cocoacontrols.com/platforms/ios/controls/bbutton" rel="nofollow">http://www.cocoacontrols.com/platforms/ios/controls/bbutton</a><p><a href="http://www.cocoacontrols.com/platforms/ios/controls/psstorebutton" rel="nofollow">http://www.cocoacontrols.com/platforms/ios/controls/psstoreb...</a><p><a href="http://www.cocoacontrols.com/platforms/ios/controls/gloss-caustic-shader" rel="nofollow">http://www.cocoacontrols.com/platforms/ios/controls/gloss-ca...</a>
DHowett超过 12 年前
I'd like to throw in the minor nitpick that stretchable/capped images are not iOS 5+, but in fact date back to iPhoneOS 2.0, with -[UIImage stretchableImageWithLeftCapWidth:topCapHeight:]<p>All said and done, however, how is "here, use the APIs provided to you, or draw the graphics yourself" at all "taming" UIButton?
millerm超过 12 年前
Nice article. I'm still excited about getting my first beta of Pixate (<a href="http://www.pixate.com/" rel="nofollow">http://www.pixate.com/</a>). I saw that kickstarter project here and bought in, twice (they had lowered the goal). Then we'll have a new way of customizing iOS controls. I did get the shirt, but I'd really the the beta. It should be coming any day now.
评论 #4645304 未加载
Inebas超过 12 年前
Not connected to the tutorial but I was trying to look at their other posts and I seem to get redirected to their learn.thoughtbot.com where they show their books, webcasts, and workshops which isn't bad but I just want to read their other posts.<p>Does anyone know how?
drp4929超过 12 年前
Any thoughts on performance impact, on the app responsiveness, of each approach ?
评论 #4646375 未加载
allr超过 12 年前
Any similar tutorial/article for styling UITableView? Always struggled with custom cells (specially grouped cells)
评论 #4645222 未加载
评论 #4645665 未加载