我在屏幕的中心有一个圆圈,我在这个固定的圆圈(一个 UIImageView)周围分配了一系列 UIlabels。标签的数量由 NSMutableArray 中元素的数量给出,标签的位置取决于标签的数量。我不能给标签一个固定的 x 和 y 坐标,因为标签的数量会有所不同。
我尝试使用此代码:
- (void)loadContent{
NSString *filename6 = [[NSUserDefaults standardUserDefaults]objectForKey:@"Setting"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *groupPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", filename6]];
NSString *fileContent = [[NSString alloc] initWithContentsOfFile:groupPath];
NSMutableArray* array = [[NSMutableArray alloc] initWithArray:[fileContent componentsSeparatedByString:@", "]];
int arrayCount = array.count;
int yCoordinate = (2*M_PI) / arrayCount;
int xCoordinate = ;
for(int i = 0; i < [array count]; i++){
CGRect textframe = CGRectMake( the xcoordinate, the ycoordinate, 328, 30);
NSString *nameOfGroup = [array objectAtIndex:i];
UITextView* theGroupTextLabel;
theGroupTextLabel = [[UITextView alloc] initWithFrame: textframe];
[theGroupTextLabel setText: nameOfGroup];
[theGroupTextLabel setTextColor: [UIColor redColor]];
[self.view addSubview:theGroupTextLabel];
//theGroupTextLabel.enabled = NO;
theGroupTextLabel.backgroundColor = [UIColor clearColor];
theGroupTextLabel.layer.borderWidth = 3.5f;
theGroupTextLabel.layer.borderColor = [[UIColor blackColor] CGColor];
int z;
z = z + 1;
theGroupTextLabel.tag = z;
}
}
但我坚持要找到正确的方程:
int yCoordinate = (2*M_PI) / arrayCount;
int xCoordinate = ;
...坐标。有任何想法吗?这是我使用的正确方法吗?