iCulture forum | iPhone, iPad,  iPod touch, Apple TV en iOS

iCulture forum | iPhone, iPad, iPod touch, Apple TV en iOS (https://forum.iculture.nl/)
-   Ontwikkelen voor iOS (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/)
-   -   cell setBackgroundColor (https://forum.iculture.nl/f133/development/f58/ontwikkelen-voor-ios/62810-cell-setbackgroundcolor.html)

Alwinkov 25-06-10 23:34

cell setBackgroundColor
 
Beste Dev's

Is het volgende ook mogelijk met een simpele code tussen de twee cellen:
(Eerste cell is wit, tweede cell is blauw, dus even cellen en oneven cellen.

Code:

// (Cell 1) Eerste cell is wit
        [cell setBackgroundColor:[UIColor whiteColor]];

// (Cell 2) Tweede cell is blauw
        [cell setBackgroundColor:[UIColor blueColor]];

// Derde cell is weer (cell 1)

// Vierde cell is weer (cell 2)


Ik had al op het internet gezocht naar een oplossing maar kwam er niet uit. (Ik heb ook het boek: Apps maken voor de iPhone gekocht, en leer steeds bij.):d Hoop dat iemand mij kan helpen.

Alwinkov

JWVD 26-06-10 12:32

Je zou in je cellForRowAtIndexPath: kunnen kijken of het rownummer even of oneven is.

Code:

if(indexPath.row % 2 == 0) {
[cell.contentView setBackgroundColor:[UIColor blueColor]];
} else {
[cell.contentView setBackgroundColor:[UIColor redColor]];
}


Alwinkov 26-06-10 23:02

Het werkt, bedankt! :d

De kleur zou ik graag nog een verloop willen mee geven.

Code:

UIColor redColor
//Deze code maakt een mix van kleuren maar is dat ook mogelijk dat boven en onder een kleurverschil in komt?

Code:

[UIColor colorWithRed:.6 green:.42 blue:.7 alpha:2]];

Kwam het volgende tegen op het internet: (NSColor mogelijk om toevoegen of word dat ergens anders voor gebruikt?

Code:

NSColor* gradientBottom = [NSColor colorWithCalibratedWhite:0.10 alpha:1.0];
NSColor* gradientTop    = [NSColor colorWithCalibratedWhite:0.35 alpha:1.0];
bgGradient = [[NSGradient alloc] initWithStartingColor:gradientBottom endingColor:gradientTop];


JWVD 27-06-10 04:59

Kijk hier eens naar.

Alwinkov 27-06-10 15:26

Heb de tut doorgelezen en het het project bekeken. Maar kom er niet uit.:(

- Is het handigste om deze code in ViewTableViewController.m te zeten of daar een nieuwe file voor aan te maken ? (Want weet niet precies hoe ik deze in mijn ViewTableViewController.m kan krijgen...(want sommige code bestaat nog niet)

Code:

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

//
// Stretch and place the origin shadow
//
CGRect originShadowFrame = originShadow.frame;
originShadowFrame.size.width = self.frame.size.width;
originShadowFrame.origin.y = self.contentOffset.y;
originShadow.frame = originShadowFrame;

[CATransaction commit];

Code:

NSIndexPath *firstRow = [indexPathsForVisibleRows objectAtIndex:0];
if ([firstRow section] == 0 && [firstRow row] == 0)
{
    UIView *cell = [self cellForRowAtIndexPath:firstRow];
    if (!topShadow)
    {
        topShadow = [[self shadowAsInverse:YES] retain];
        [cell.layer insertSublayer:topShadow atIndex:0];
    }
    else if ([cell.layer.sublayers indexOfObjectIdenticalTo:topShadow] != 0)
    {
        [cell.layer insertSublayer:topShadow atIndex:0];
    }

    CGRect shadowFrame = topShadow.frame;
    shadowFrame.size.width = cell.frame.size.width;
    shadowFrame.origin.y = -SHADOW_INVERSE_HEIGHT;
    topShadow.frame = shadowFrame;
}
else
{
    // Remove the shadow if it isn't visible
    [topShadow removeFromSuperlayer];
    [topShadow release];
    topShadow = nil;
}


Code:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    self.textLabel.backgroundColor = [UIColor clearColor];
    self.detailTextLabel.backgroundColor = [UIColor clearColor];
}


JWVD 27-06-10 16:56

Als je alleen een gradient onder je UITableViewCell wilt kan je toch de UITableViewCell-class van hun project kopiëren?

Alwinkov 27-06-10 18:12

ShadowedTableView app
Code:

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    static NSString *CellIdentifier = @"Cell";
   
    UITableViewCell *cell =
                [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[ClearLabelsCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                cell.backgroundView = [[[GradientView alloc] init] autorelease];
    }
   
        UILabel *label = cell.textLabel;
        NSLog(@"UILabel is %@", label);
        cell.textLabel.text = [NSString stringWithFormat:@"Some text for row %ld", indexPath.row + 1];
       
    return cell;
}

Mijn code:
Code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *MyIdentifier = @"MyIdentifier";
        MyIdentifier = @"TableView";
       
        MainView *cell = (MainView *)[tableView dequeueReusableCellWithIdentifier: MyIdentifier];
       
       
       
        if(cell == nil) {
                [[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil];
                cell = tableCell;
               
        }
       
        [cell LabelText:[arryList objectAtIndex:indexPath.row]];
        [cell ProductImage:[imagesList objectAtIndex:indexPath.row]];
       
        if(indexPath.row % 2 == 0) {
        [        cell.contentView setBackgroundColor:[UIColor darkGrayColor]];       
               
        } else {
                [cell.contentView setBackgroundColor:[UIColor lightGrayColor]];
               
        }

        return cell;
       
}


Deze code ergens tussen zeten ?
Code:

if (cell == nil) {
        cell = [[[ClearLabelsCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                cell.backgroundView = [[[GradientView alloc] init] autorelease];
    }


JWVD 27-06-10 19:54

Jep. Volgensmij moet het werken als je die laatste code in je cellForRowAtIndexPath: zet ;)

Alwinkov 27-06-10 20:19

Zou je misschien kunnen laten zien hoe die code er dan zou moeten uit zien, want hij crashed...

Alwinkov 01-07-10 14:52

Of kan ik beter twee images toevoegen?

Wat wel weer als nadeel heeft dat de app wat groter word...en misschien wat langzamer is...

wubbe 01-07-10 16:01

Je kunt ook een custom UITableCell in Interface Builder maken.
Lijk mij makkelijker.


Alle tijden zijn GMT +2. Het is nu 21:06.