简体   繁体   中英

UIView not filling its frame

I'm trying to use this XYPieChart here, the demo works great and it looks beautiful. Problem is, whenever I try to recreate it on a Storyboard, the chart appears incredibly small and I can't seem to resize it. I've played around with all the settings and set the frame of the property and nothing seems to work. I've tried resizing it to the entire screen with:

[self.pieChart setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

Still the same result except the frame stretches across the screen and everything is grey. Anyone, this is how it's coming out, the grey is the frame and the XYPieChart loads in the center:

I'm still fairly new and I've been searching how to remedy this but I can't formulate a good enough search query that makes sense.

It looks like you haven't set the pieRadius property on the chart.

If you change this it should make the pie bigger.

The problem is due to AutoLayout. If you want to keep using AutoLayout in your project, you can simply change your viewDidAppear this way:

- (void)viewDidAppear:(BOOL)animated {

    self.pieChart.pieRadius = MIN(self.pieChart.frame.size.width/2, self.pieChart.frame.size.height/2) - 10;
    self.pieChart.self.pieCenter = CGPointMake(self.pieChart.frame.size.width/2, self.pieChart.frame.size.height/2);
    self.pieChart.labelRadius = self.pieChart.pieRadius/2;
    self.pieChart.labelFont = [UIFont boldSystemFontOfSize:MAX((int)self.pieChart.pieRadius/10, 5)];


    [self.pieChart reloadData];

}

At the moment viewDidAppear will be called, your pieChart frame will be already updated with sizes provided by AutoLayout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM