2015-10-09 64 views
0

我正在使用FSCalendar我想要做的是改變顯示事件的方式。我想用事件在單元格周圍放置一個彩色的矩形邊框。我是通過編輯單元格背景圖層來完成的,並且工作正常,但現在我意識到將代碼更新爲最新版本的FSCalendar將覆蓋我的更改是錯誤的。 我可以通過日曆代表訪問的內容之一是將圖像設置爲單元格,所以我想用事件顏色創建圖像作爲rectange邊框。 這裏是我想要的圖像: Calendar With events as rectangle border創建UIImage作爲邊框顏色

任何建議都是適用的。 在此先感謝。

回答

3

這種方法會得出邊矩形。爲了方便使用,我將它製作成類方法並放入UIImage類中。

- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)imageSize andBorderWidth:(CGFloat)borderWidth fillWithColor:(BOOL)fillWithColor{ 

    UIGraphicsBeginImageContext(imageSize); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGRect rect = CGRectMake(0, 0, imageSize.width, imageSize.height); 

    if(fillWithColor) { 
     [color setFill]; 
     CGContextFillRect(context, rect); 
    } else { 
     [color setStroke]; 
     CGContextStrokeRectWithWidth(context, rect, borderWidth); 
    } 

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return image; 
} 

編輯:添加fillWithColor參數

+0

像魅力一樣工作。謝謝 – Ismail

1

您可以設置邊框的UIImageView,而不是設定的圖像作爲rectange邊境

cell.imageView.layer.borderColor = [[UIColor redColor] CGColor]; 
cell.imageView.layer.borderWidth = 1.0f; 
+0

感謝你的快速答覆。我沒有訪問圖像視圖的東西我只是在委託方法中返回一個UIImage。 – Ismail