하위 클래스 UITableViewCell
안에 서브 클래스 UIButton
이 있습니다. 단추는 펜촉에서로드됩니다.CALayer 렌더링 또는 그리기가 없음
버튼이있는 이미지로 사용하고 싶습니다. 애니메이션에 대한 더 많은 제어를 위해 CALayer
을 사용하고 싶습니다. 사용자가 버튼을 탭하면 애니메이션이 발생합니다. 그러나, 나는 심지어 이미지가 나타나기까지 할 수 없다.
QuartzCore를 가져 왔습니다. 내 UIButton
를 서브 클래스 (항상 펜촉에서로드)의
코드 :
-(void)awakeFromNib {
[super awakeFromNib];
self.clipsToBounds = NO;
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
self.userInteractionEnabled = YES;
}
코드 테이블 뷰 컨트롤러는 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomCell *cell = (BLCustomCellCenter*)[tableView dequeueReusableCellWithIdentifier:@"customCellID"];
if (cell == nil) {
// ... cell is initialized
}
// configure the image for the button
//
// Note: there is an outlet to the UIButton called 'customButton'
CALayer *imgLayer = [CALayer layer];
imgLayer.bounds = CGRectMake(0, 0, cell.customButton.bounds.size.width, cell.customButton.bounds.size.height);
imgLayer.position = CGPointMake(cell.customButton.bounds.size.width/2, cell.customButton.bounds.size.height/2);
UIImage *img = [UIImage imageNamed:@"someImage"];
imgLayer.contents = (id)[img CGImage];
[cell.customButton.layer addSublayer:imgLayer];
// ... configure subviews of 'customButton'
return cell;
}
어떤 도움은 매우 언제나처럼, 감사합니다.
아니, 그런 행운. –
img가 0이 아닌 것을 확인 했습니까? –
그것은 0이 아닙니다. NSLog는 ""과 같은 피드백을 제공합니다. –