我在屏幕中心有一個圓圈,我在這個固定圓圈(一個UIImageView)周圍分配了一系列UIlabels。標籤的數量由NSMutableArray中元素的數量給出,標籤的位置取決於標籤的數量。我無法給標籤賦予固定的x和y座標,因爲標籤的數量會有所不同。在特定位置分配UITextViews
我嘗試使用此代碼:
- (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 = ;
...座標。有任何想法嗎?這是我正在使用的正確方法嗎?
這些標籤是如何定位的?在網格中?或者它們圍繞圖像周圍環繞(如時鐘表面上的數字)?我注意到你有一個M_PI,所以我猜它就像一個時鐘? – Kekoa
在圖像中以圓圈形式顯示,如同時鐘 – Alessandro