0

I'm writing my calendar using UICollectionView. i don't know why this line come out

enter image description here

this is my code for create UICollectionView

#import "MonthTableView.h"
#import "MonthTableCollectionViewCell.h"

@implementation MonthTableView

static NSString *sCELLIDENTIFIER = @"cellidentifier";

#pragma mark - View Lifecycle

-(MonthTableView *)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];

    if (self) {

        _arr_Week = @[@"日",@"一",@"二",@"三",@"四",@"五",@"六",];

        [self initSubView];
    }

    return self;
}

-(void)initSubView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing      = 0;

    UICollectionView *col_Month = [[UICollectionView alloc]initWithFrame:CGRectMake(5, 5, self.frame.size.width - 10, self.frame.size.height - 10) collectionViewLayout:flowLayout];

    col_Month.dataSource = self;
    col_Month.delegate   = self;

    [self addSubview:col_Month];


    [col_Month registerClass:[MonthTableCollectionViewCell class] forCellWithReuseIdentifier:sCELLIDENTIFIER];
}

#pragma mark - UICollectionView Delegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return 7;
    }
    else {
        return 5*7;
    }
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    CGFloat width = collectionView.frame.size.width / 7;
    return CGSizeMake(width, width);
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MonthTableCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:sCELLIDENTIFIER forIndexPath:indexPath];

    //Debug
    if (indexPath.section == 0) {
        cell.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
        [cell.btn_Day setTitle:[NSString stringWithFormat:@"%@",_arr_Week[indexPath.row]] forState:UIControlStateNormal];
    }
    else
    {

    cell.btn_Day.backgroundColor = [UIColor whiteColor];
    [cell.btn_Day setTitle:[NSString stringWithFormat:@"%ld",indexPath.row] forState:UIControlStateNormal];
    }

    return cell;
}




@end

And here is my Custom cell

#import "MonthTableCollectionViewCell.h"

@implementation MonthTableCollectionViewCell

-(MonthTableCollectionViewCell *)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];

    if (self) {
        [self initSubViews];
    }
    return self;
}

-(void)initSubViews
{
    _btn_Day = [UIButton buttonWithType:UIButtonTypeSystem];
    _btn_Day.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);

    [self addSubview:_btn_Day];
}
@end

there is nothing in .h file but declaring vars BTW i'm using Xcode6.

Wythe
  • 149
  • 3
  • 12
  • I think this is a bug or something that cannot handled correctly. Because for a second think the width which is 320, divide by 7, the result is 45.711428... never finishes. I think the system at a specific point stops the calculations and makes approximations. And that is the pixel approximated which I think is giving you the lines. – E-Riddie Oct 15 '14 at 14:39
  • I make it to number 45,the line is still there – Wythe Oct 15 '14 at 23:52
  • You are making an approximation, that is normal that you are going to have lines, because you have unfilled pixels, which show up as lines. Try 8 cells per row, by diving self.width/8 on width of each cell – E-Riddie Oct 16 '14 at 08:14

0 Answers0