是否在文ios中有任何变化来调整CCCLabelTTF的两条线路之间的距离。 增 编
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices for using SKPaymentQueue s restoreCompletedTransactions? Observations I know it s recommended to always ...
是否在文ios中有任何变化来调整CCCLabelTTF的两条线路之间的距离。 增 编
回答你的问题。 您可以调整CCCLabelTTF线路。 But! 我将同你分享我的解决方案。
就是这样。 h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface CCLabelTTFLineSpaced : CCLayer {
}
+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space;
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space;
@end
这也是事实。 页: 1
#import "CCLabelTTFLineSpaced.h"
@implementation CCLabelTTFLineSpaced
+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space{
return [[[self alloc] initWithString: string dimensions:dimensions alignment:alignment fontName:name fontSize:size lineSpace:(CGFloat)space]autorelease];
}
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions alignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space{
if( (self=[super init]) ) {
anchorPoint_ = ccp(0.5f, 0.5f);
[self setContentSize:dimensions];
self.isRelativeAnchorPoint = NO;
int pos = 0;
int i = 0;
while (pos<[str length]) {
int end = 0;
int lastCut = -1;
bool finished=NO;
while (finished==NO) {
CGSize actualSize = [[str substringWithRange:NSMakeRange(pos, end)] sizeWithFont:[UIFont fontWithName:name size:size]];
if (actualSize.width > dimensions.width || pos+end == [str length]) {
if (pos+end == [str length] && actualSize.width <= dimensions.width) lastCut = end;
finished=YES;
}
else {
if ([[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@" "] || [[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@"."] || [[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@","]) {
lastCut = end;
}
end++;
}
}
NSString * strLine = [str substringWithRange:NSMakeRange(pos, lastCut)];
CCLabelTTF * line = [CCLabelTTF labelWithString:strLine dimensions:CGSizeMake(dimensions.width, size*2) alignment:alignment fontName:name fontSize:size];
[line setAnchorPoint:ccp(0,1)];
[line setPosition:ccp(0,-i*space)];
[self addChild:line];
pos=pos+lastCut;
i++;
}
}
return self;
}
@end
a. 便于使用; 我必须用洗衣机、 set机和所有 st子完成这一班级。 我知道,这是一个“本土”解决办法,但令人 he! 它发挥作用!
对于有2d 2.x的可可公司,我修改了@Hardschool法,以固定假造方法,并努力工作!
页: 1 h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface CCLabelTTFLineSpaced : CCLayer {
}
+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions hAlignment: (CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space;
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space;
@end
页: 1
#import "CCLabelTTFLineSpaced.h"
@implementation CCLabelTTFLineSpaced
+ (id) labelWithString:(NSString*)string dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space{
return [[[self alloc] initWithString: string dimensions:dimensions hAlignment:alignment fontName:name fontSize:size lineSpace:(CGFloat)space]autorelease];
}
- (id) initWithString:(NSString*)str dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment fontName:(NSString*)name fontSize:(CGFloat)size lineSpace:(CGFloat)space{
if( (self=[super init]) ) {
anchorPoint_ = ccp(0.5f, 0.5f);
[self setContentSize:dimensions];
self.ignoreAnchorPointForPosition = YES;
int pos = 0;
int i = 0;
while (pos<[str length]) {
int end = 0;
int lastCut = -1;
bool finished=NO;
while (finished==NO) {
CGSize actualSize = [[str substringWithRange:NSMakeRange(pos, end)] sizeWithFont:[UIFont fontWithName:name size:size]];
if (actualSize.width > dimensions.width || pos+end == [str length]) {
if (pos+end == [str length] && actualSize.width <= dimensions.width) lastCut = end;
finished=YES;
}
else {
if ([[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@" "] || [[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@"."] || [[str substringWithRange:NSMakeRange(pos+end, 1)] isEqualToString:@","]) {
lastCut = end;
}
end++;
}
}
NSString * strLine = [str substringWithRange:NSMakeRange(pos, lastCut)];
CCLabelTTF * line = [CCLabelTTF labelWithString:strLine dimensions:CGSizeMake(dimensions.width, size*2) hAlignment:alignment fontName:name fontSize:size];
[line setAnchorPoint:ccp(0,1)];
[line setPosition:ccp(0,-i*space)];
[self addChild:line];
pos=pos+lastCut;
i++;
}
}
return self;
}
@end
感谢@Hardschool!
gmoegas, 这里称为“Color”
void CCLabelTTFLineSpaced::setColor(ccColor3B color)
{
for (int i = 0; i < getChildren()->count(); i ++)
{
CCLabelTTF* child = (CCLabelTTF*)getChildren()->objectAtIndex(i);
child->setColor(color);
}
}
我认为,这是一个问题,许多可可2d开发商 st倒。 因此,为了改进这一类的可读性和协作性,我正在为之建立一个Github存放处。
我开始在@gmoagames(and @Hardschool)的版本上添加了setColor:
。 “Alex”方法,并增加了一种方法,以纠正不透明性。
如果你有一些改进,我可以自由提出合并要求。
许多人感谢在这里分享的所有法典。
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices for using SKPaymentQueue s restoreCompletedTransactions? Observations I know it s recommended to always ...
I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...
I have a UITextField that is a subview of a UITableViewCell. When my view loads, I want the text field to become first responder. I have a pointer to the text field in the table cell, so to do this I ...
I ve been working on adding in-app purchases and was able to create and test in-app purchases using Store Kit (yay!). During testing, I exercised my app in a way which caused the app to crash mid ...
In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...
Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...
I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...
Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...