Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在核心图中居中多行标签,iOS_Ios_Objective C_Core Plot_Labels - Fatal编程技术网

在核心图中居中多行标签,iOS

在核心图中居中多行标签,iOS,ios,objective-c,core-plot,labels,Ios,Objective C,Core Plot,Labels,我正在做一个核心地块项目,遇到了一个问题。我的X轴标签都不止一行。我希望它们完全居中,到目前为止,我唯一能够做到这一点的方法是手动将空格添加到作为标签的NSString中。请看下面的代码 NSDictionary *dataTemp=[NSDictionary dictionaryWithObjectsAndKeys:white,@" White\rBuilding\r(220 max)",rec,@"Rec. Hall\r(240 max)",im,@" IM\rBuil

我正在做一个核心地块项目,遇到了一个问题。我的X轴标签都不止一行。我希望它们完全居中,到目前为止,我唯一能够做到这一点的方法是手动将空格添加到作为标签的NSString中。请看下面的代码

 NSDictionary *dataTemp=[NSDictionary dictionaryWithObjectsAndKeys:white,@"      
 White\rBuilding\r(220 max)",rec,@"Rec. Hall\r(240 max)",im,@"    IM\rBuilding\r(60 
 max)",fit,@"Fitness\r   Loft\r(40 max)",nil];
我认为有一种方法可以通过编程方式对齐标签,但我还没有找到它。我非常感谢你的帮助。下面是图形标签的屏幕截图

这是我定义x轴标签的代码

//Array containing all the names that will be displayed on the X axis
dates = [NSArray arrayWithObjects:@"Rec. Hall\r(240 max)", @"  White\rBuilding\r(220 
max)", @"    IM\rBuilding\r(60 max)",
         @"Fitness\r   Loft\r(40 max)",  nil];
这是我在图表上做标签的代码

 //X labels
int labelLocations = 0;
NSMutableArray *customXLabels = [NSMutableArray array];
for (NSString *day in dates) {
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:day 
textStyle:x.labelTextStyle];
    newLabel.tickLocation   = [[NSNumber numberWithInt:labelLocations] decimalValue];
    newLabel.offset         = x.labelOffset + x.majorTickLength;
    [customXLabels addObject:newLabel];
    labelLocations++;
    [newLabel release];
}
x.axisLabels                    = [NSSet setWithArray:customXLabels];

这应该行得通-您应该尝试在标签上使用
textAlignment
属性:

label.textAlignment = NSTextAlignmentCenter; 
正如@Martin所指出的,您还可以添加
UILineBreakModeWordWrap
,这样换行符只出现在整个单词之后:

label.lineBreakMode = UILineBreakModeWordWrap;

这应该行得通-您应该尝试在标签上使用
textAlignment
属性:

label.textAlignment = NSTextAlignmentCenter; 
正如@Martin所指出的,您还可以添加
UILineBreakModeWordWrap
,这样换行符只出现在整个单词之后:

label.lineBreakMode = UILineBreakModeWordWrap;

确保创建标签时使用的文本样式(
x.labelTextStyle
)包括以下属性设置:

textStyle.textAlignment = CPTTextAlignmentCenter;

确保创建标签时使用的文本样式(
x.labelTextStyle
)包括以下属性设置:

textStyle.textAlignment = CPTTextAlignmentCenter;

并添加NSLinebreakByWordWrapping,以便在整个WordsOrry中发生换行,但不起作用…我编辑了我的帖子,以包含更多代码。我认为我创建标签的方式有问题。当我尝试执行newLabel.textAlignment时,它不起作用。@pj409尝试使用labelAlignment=CPAlignmentCenter;查看此链接--请确保单击“全部展开”并添加NSLinebreakByWordWrapping,以便在整个WordsOry中发生换行,但这不起作用…我编辑了我的文章,以包含更多代码。我认为我创建标签的方式有问题。当我尝试执行newLabel.textAlignment时,它不起作用。@pj409尝试使用labelAlignment=CPAlignmentCenter;并查看此链接--确保单击“全部展开”