顯示具有 iOS 標籤的文章。 顯示所有文章
顯示具有 iOS 標籤的文章。 顯示所有文章

2012年4月19日 星期四

根據內容多寡,調整cell高度

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


cell.textLabel.text=[[theArray objectAtIndex:indexPath.row] objectForKey:@"description"];
cell.textLabel.lineBreakMode=UILineBreakModeTailTruncation; //若內容超出cell可容納範圍,最後出現"..."
cell.textLabel.numberOfLines=30; //單一cell出現的行數,0為無限

return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [[theArray objectAtIndex:indexPath.row] objectForKey:@"description"];

//開始去計算全部內容,以字體大小14、lineBreakMode:UILineBreakModeTailTruncation狀態下,會得到多少的範圍寬高度
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0, 480.0) lineBreakMode:UILineBreakModeTailTruncation];
//CGSizeMake(240.0, 480.0) 設定單一cell最大的寬高度,若得到的size超過這個範圍,則只會以這個為基準;

return MAX(size.height + 10, 40.0f); //單一cell高度最小會為40

}



UIViewContentModeScaleAspectFill後將多餘區域切除

UIImage *image = [UIImage imageNamed:@"image.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 180, 300, 150)];
imageView.image = image;
imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:imageView];


若該imgae的高度大於150
雖然使用了UIViewContentModeScaleAspectFill
仍會顯示完整的圖片
若要只限定出現150高度範圍內的圖片
需多加一段語法即可實現
imageView.clipsToBounds = YES;

若是使用xib將Mode設為Scale To Fill時
請勾選Clip Subviews即可有相同效果


轉載整理自:難纏的兔子王 - UIViewContentModeScaleAspectFill的陷阱


2012年1月6日 星期五

Snakes & Ladders !

源自於印度的桌上遊戲,棋盤上除方格外,還會有梯子、蛇。
以骰子隨機決定棋子的步數,途中若抵達梯子或蛇的格子會移至其他格,以抵達終點為勝利。

Snakes & Ladders ! 1.3 更新
1.增加儲存遊戲/讀取遊戲功能
2.更改程式內的遊戲名稱圖片
3.對版面做些微調



“Snakes & Ladders !” for iPhone and iPad

http://itunes.apple.com/app/id489788712