Ustawianie promienia narożnika w interfejsie UIImageView nie działa
Jestem trochę zagubiony. Użyłem właściwości warstwy UIView do zaokrąglania rogów wielu elementów w mojej aplikacji. Jednak ten jeden UIImageView po prostu nie jest zgodny. Nie wiem, co mi umyka.
Interfejs UIImageView (zwany podglądem) jest zawarty w komórce widoku tabeli. Próbowałem ustawić właściwość cornerRadius wiele lokalizacji (w samej komórce i w kontrolerze, który tworzy komórkę) bez skutku.
static NSString *CellIdentifier = @"MyTableViewCell";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
cell.previewImage.layer.cornerRadius = 20; //Made it 20 to make sure it's obvious.
}
Czy jest coś w sposobie, w jaki komórki są załadowany, że brakuje?
7 answers
Musisz ustawić właściwość masksToBounds
warstwy na YES
:
cell.previewImage.layer.masksToBounds = YES;
Dzieje się tak dlatego, że kontrolka UIImageView
tworzy pseudo-podgląd do przechowywania obiektu UIImage
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-30 19:36:00
To powinno zadziałać
cell.previewImage.clipsToBounds = YES;
cell.previewImage.layer.cornerRadius = 20;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-06 09:34:27
Warto również zauważyć, że
- jeśli używasz aspectFit i cornerRadius z clipsToBounds / masksToBounds, nie otrzymasz zaokrąglonych rogów.
Czyli jeśli masz to
theImageView.contentMode = .scaleAspectFit
I
theImageView.layer.cornerRadius = (theImageView.frame.size.height)/2
theImageView.clipsToBounds = true
Lub
theImageView.layer.masksToBounds = true
Tonie zadziała . będziesz musiał pozbyć się kodu aspectFit
//theImageView.contentMode = .scaleAspectFit
- upewnij się, że szerokość i wysokość widoku obrazu są takie same
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-22 14:23:04
Uważam, że trzeba ustawić:
cell.previewImage.layer.masksToBounds = YES;
cell.previewImage.layer.opaque = NO;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-30 14:20:09
W Xcode Interface Builder, wybranie atrybutu' Clip Subviews ' rysunku dla widoku wraz z ustawieniem promienia rogu w kodzie cell.previewImage.layer.cornerRadius = 20;
robi to za mnie!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-09 01:38:48
Wypróbuj poniższy fragment kodu
cell.previewImage.layer.cornerRadius = 20;
cell.previewImage.clipsToBounds = YES;
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-20 15:31:55
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self setMaskTo:viewDistance
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight];
}
- (void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners
{
UIBezierPath *rounded = [UIBezierPath
bezierPathWithRoundedRect:view.bounds
byRoundingCorners:corners
cornerRadii:CGSizeMake(20.0, 20.0)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
shape.frame = self.view.bounds;
[shape setPath:rounded.CGPath];
view.layer.mask = shape;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-18 07:16:50