Hello,I'm new to cocoa and macruby, I want to start a tweetie-like app to learn macruby & cocoa, when display status list,I use NSTableView,and I must calculate the row height with `def tableView(table,heightOfRow:row);end` myself ,right? After googled a while,I found the way ,like this: framework 'cocoa' class String def height_with_width(width=100) attributes = {} attributes[NSFontAttributeName.to_sym] = NSFont.fontWithName("Lucida Grande", size:12) attributes[NSParagraphStyleAttributeName.to_sym] = NSParagraphStyle.defaultParagraphStyle text_storage = NSTextStorage.alloc.initWithString(self) text_container = NSTextContainer.alloc.initWithContainerSize([width,1000]) layout_manager = NSLayoutManager.alloc.init layout_manager.addTextContainer(text_container) text_storage.addLayoutManager(layout_manager) text_storage.addAttributes(attributes, range:NSMakeRange(0, text_storage.length)) text_container.setLineFragmentPadding(0.0) layout_manager.glyphRangeForTextContainer(text_container) layout_manager.usedRectForTextContainer(text_container).size.height end end puts "a".height_with_width #15 puts "b".height_with_width #15 puts "ab".height_with_width #15 puts "中".height_with_width #18 puts "ak中".height_with_width #19 puts "ak中".height_with_width(1) #15+15+18 because the chinese characters, the height of a line is diffence, I want it to be same ,like all return 19 , How Can I Fix This ? HELP!
On Tue, Jun 22, 2010 at 06:01, niedhui <niedhui@gmail.com> wrote:
because the chinese characters, the height of a line is diffence, I want it to be same ,like all return 19 , How Can I Fix This ? HELP!
I have no idea if you can force the line height to be the same in entire text... But if I can recommend something, I'm also writing a Tweetie-like app (more like a Tweetie clone, but for a different network, a Polish one); and I found this library very useful: http://github.com/sdegutis/SDListView - it's a replacement of NSTableView which lets you use normal NSViews as cells and is generally more modern. I read a blog post some time ago by a guy who tried various approaches before writing such app and he wrote that NSTableView was a bad idea, because sooner or later you run into limitations of NSCell and it gets annoying... (here's the post: http://flyosity.com/application-design/sneak-peek-beak-10-for-mac-iphone.php). JS
One warning, it uses blocks, so if you want to use it on 10.5, you'd have to make a few changes in it. JS
Also.. using NSView instances instead of cells will use much more memory and will probably be slower to draw, so be careful if you have a complicated table view. - Matt On Tue, Jun 22, 2010 at 12:46 AM, Jakub Suder <jakub.suder@gmail.com> wrote:
One warning, it uses blocks, so if you want to use it on 10.5, you'd have to make a few changes in it.
JS _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
thank you,it helps a lot On Jun 22, 2010, at 3:46 PM, Jakub Suder wrote:
One warning, it uses blocks, so if you want to use it on 10.5, you'd have to make a few changes in it.
JS _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (3)
-
Jakub Suder
-
Matt Aimonetti
-
niedhui