In my tableView cell, theres a backgroundcolor on my text, and i have no clue on how to remove it.. Can some one help me here ?
I've tried
cell.backgroundColor = [UIColor clearColor];
cell.opaque = NO;
but aint working
Have you tried:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.opaque = NO;
and:
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.opaque = NO;
Related
How can scroll performance of a UITextView be improved when using attributed strings? The following sample code results in completely unacceptable performance on an iPad 3.
NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];
pStyle.lineSpacing = 14.0;
pStyle.lineHeightMultiple = 20;
pStyle.maximumLineHeight = 20.0;
pStyle.minimumLineHeight = 20.0;
UIFont *font = [UIFont systemFontOfSize:20.0];
NSDictionary *attributes = #{ NSFontAttributeName : font, NSParagraphStyleAttributeName : pStyle};
NSMutableAttributedString *newline = [[NSMutableAttributedString alloc] initWithString:#"\n\n"];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:#"" attributes:#{}];
for (int paragraph=0; paragraph<300; paragraph++){
for (int word=0; word<100; word++){
[string appendAttributedString:[[NSAttributedString alloc] initWithString:#"text!"]];
}
[string appendAttributedString:newline];
}
[string setAttributes:attributes range:NSMakeRange(0, string.length)];
self.textView.attributedText = string;
I should mention that I am open to using Text Kit, but I wouldn't know where to start to ensure that performance is ultimately ok. Also, here's what's going on in the profiler while scrolling.
Two things help here.
First, I only needed the lineSpacing style set. Setting any of the other paragraph parameters results in slow scrolling.
The second was to call [self.textView.layoutManager ensureLayoutForCharacterRange:NSMakeRange(0, self.textView.attributedText.length)]; in viewDidAppear:. Otherwise the first time you scroll through the document it is jerky.
I have recently coded in a menu item, the "Game Over" Label appears but the menu item "Restart" isn't. I have no idea why?
Can anyone help, here is whats in my method !
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCLabelTTF *label = [CCLabelTTF labelWithString:#"Game Over"
fontName:#"Marker Felt"
fontSize:64];
label.color = ccRED;
label.position = ccp(winSize.width*0.5, winSize.height*0.75);
[self addChild:label];
CCMenuItem *item = [CCMenuItemFont itemWithString:#"Restart"
target:self
selector:#selector(restartGame)];
CCMenu *menu = [CCMenu menuWithItems:item, nil];
[menu alignItemsVertically];
[self addChild:menu];
try this code:
menu.position = ccp(winSize.width/2, winSize.height/2);
set the specific position.
Before insert image in uipickerview
After insert image in uipickerview
- (UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
CGRect imageFrame = CGRectMake(0.0, 0.5, 255, 250);
UIImageView *label = [[UIImageView alloc]
initWithFrame:imageFrame];
label.backgroundColor=[UIColor scrollViewTexturedBackgroundColor];
[label sendSubviewToBack:pview];
[pview sendSubviewToBack: label];
[pview addSubview:label];
return label;
}
In your code you have written this:-
[label sendSubviewToBack:pview];
[pview sendSubviewToBack: label];
I think you are doing mistake here..
you just use this:-
[label sendSubviewToBack:pview];
[label addSubview:pview];
remove this
[pview sendSubviewToBack: label];
it will work fine..if not feel free to ask..enjoy..
I have a very very long text, so instead of using UITextView, I want to truncate the text to small chunks that can fit to a label with width and height 300, 400, and based on number of chunks, I want to create UILabel dynamically and populate them with these chunks.
I have written a method but it seems doesn't return the actual strings that can fit. it returns shorter strings.
am I missing something?
is there anyway I can do this?
- (NSArray *)truncate:(NSString *)text
{
NSMutableArray *textChunks = [[NSMutableArray alloc] init];
NSString *chunk = [[NSString alloc] init];
CTFramesetterRef frameSetter;
UIFont *uiFont = [UIFont systemFontOfSize:17.0f];
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)uiFont.fontName, uiFont.pointSize, NULL);
NSDictionary *attr = [NSDictionary dictionaryWithObject:(__bridge id)ctFont forKey:(id)kCTFontAttributeName];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:text attributes:attr];
CFRange fitRange;
while (attrString.length>0) {
frameSetter = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef) attrString);
CGSize framSize = CTFramesetterSuggestFrameSizeWithConstraints(frameSetter, CFRangeMake(0,0), NULL, CGSizeMake(myLabel.frame.size.width, myLabel.frame.size.height), &fitRange);
NSLog(#"height: %f", framSize.height);
CFRelease(frameSetter);
chunk = [[attrString attributedSubstringFromRange:NSMakeRange(0, fitRange.length)] string];
[textChunks addObject:chunk];
[attrString setAttributedString: [attrString attributedSubstringFromRange:NSMakeRange(fitRange.length, attrString.string.length-fitRange.length)]];
}
return textChunks;
}
Yes, you need to add a paragraph style in order to get the width/height measure to work properly. See giving-framesetter-the-correct-line-spacing-adjustment. Note how CTFontGetLeading() is used to get the font leading and then this property is set vai CFAttributedStringSetAttributes().
Is it possible to place an image in the UIWebView background instead of that gray default color. If yes then how?
Did it by myself.
self.webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:backgroundImage]];
In your viewDidLoad please Add this code for loading image at startup
[webView setOpaque:NO];
webView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"night.jpg"]];
self.webView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:imagePath]];