CCLabelTTF with fixed width and dynamic height solution
2014-08-22 11:51
671 查看
CGSize size =[[CCDirectorsharedDirector]winSize]; NSString *str = [NSString stringWithString:@" did a bit of research and was able tofind out the size of an nsstring within a constraint then applythat to the label which has worked so far for me. Hopefully thiscan help someone stuck with the same problem I was having. I dohowever get a bunch of context errors which I have no idea how tofix, but they don't seem to stop anything fromworking."]; UIFont *font = [UIFont fontWithName:@"Marker Felt" size:16]; CGSize compSize = [str sizeWithFont:font constrainedToSize:CGSizeMake(size.width *0.8,2000)lineBreakMode:UILineBreakModeWordWrap]; CCLabelTTF *label = [CCLabelTTF labelWithString:str dimensions:compSize alignment:UITextAlignmentLeft fontName:@"MarkerFelt" fontSize:16]; NSLog(@"width:%f, height:%f",compSize.width,compSize.height); label.position= ccp(size.width /2 , size.height/2 ); [self addChild: label];
相关文章推荐
- Center parent div with dynamic and set width child divs
- Charts with Dynamic Height or Width based on Categories/Data (SQL 2008, RDL)
- C# Selenium with PhantomJSDriver get image width and height (获取图片的长和高)
- Dynamic Table View Cell Height and Auto Layout
- opencv bug? cvExtractSurf fails with Non-positive width or height exception (opencv 2.1.0)
- 转帖:GTK+ programs with GtkBuilder and dynamic signal handlers.
- bitmap 缩放 java.lang.IllegalArgumentException: width and height must be > 0
- Asp.net DataGrid control with Fixed Header and Scrollbar
- About the Height and Width property of DisplayObject
- java.lang.IllegalArgumentException: width and height must be > 0
- Fragment中测量宽度、高度, Caused by: java.lang.IllegalArgumentException: width and height must be > 0
- Scraping the Dynamic Web with PhantomJS: Using jQuery and Node: James Morrin: 9781449321864: Amazon.com: Books
- Create Spring MVC dynamic web project with Maven and make it support Eclipse IDE
- How do I get dynamic DataSources with iBATIS and Spring?
- CSS 笔记一(Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width)
- Dynamic Table View Cell Height and Auto Layout
- Lintcode177 Convert Sorted Array to Binary Search Tree With Minimal Height solution 题解
- Native Client - Development Cycle - Dynamic Linking and Loading with glibc
- spring.data.jpa.query :Cannot use native queries with dynamic sorting and/or pagination in method
- SpringData JPA @Query分页查询 Cannot use native queries with dynamic sorting and/or pagination in method