It's hard for me to describe the problem, and I'll use screenshots. They are all from my simulator, when I test in my iPodTouch4
, its the same.
I have several UILabel
s, which are rects in the picture.
Notice there are black lines on the right of some rects, which is unexpected, because I didn't code any extra behavior except for backgoundColor and frame.
When I change UILabel
to UIView
(nothing else changed), every thing becomes normal!
And when use UILabel
not in retina display, we can see clearly than some rects have different width, but according to my code and the log, they have same width! Realllllly Weird!
I can't figure out why. It might be something special about UILabel
, but I can't find anywhere int the documentation.
[this is how I create labels]
NSMutableArray *labels = [NSMutableArray array];
for (NSString *day in [self getDaysOfTheWeek]) {
UILabel *dayOfWeekLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[labels addObject:dayOfWeekLabel];
}
self.dayOfWeekLabels = labels;
[this is where I set their frames]
int count = 0;
for (UILabel *dayLabel in self.dayOfWeekLabels) {
dayLabel.frame = CGRectMake(CELL_BORDER_WIDTH + count*(self.cellWidth+CELL_BORDER_WIDTH), CELL_BORDER_WIDTH, self.cellWidth, self.daysHeader.frame.size.height);
dayLabel.backgroundColor = self.dateBackgroundColor;
count++;
}
Just as I mentioned above, simply change these UILabel to UIView in these code make them looks differently.