how to bold particular word in label in iphone - iphone

What me actually doing:-
lbl1= [[UILabel alloc] init];
lbl1.frame=CGRectMake(10, 10,90, 40);
lbl1.textColor=[UIColor blackColor];
lbl1.text=#"Definitions";
lbl1.font = [UIFont boldSystemFontOfSize:16.0f];
UILabel* finalLabel=[[UILabel alloc] init];
finalLabel.frame=CGRectMake(100, 10,90, 40);
finalLabel.text=[NSString stringWithFormat:#"%#:,The following terms shall have the described meaning:",lbl1];
finalLabel.font = [UIFont fontWithName:#"Helvetica" size:14];
finalLabel.numberOfLines=2;
[self.view addSubview:lbl1];
[self.view addSubview:finalLabel];
Didn't get the proper result of final label
it print:- Definitions
UILABEL:0X68640;frame(10,10,90,40);text='Definition',CliptoBound=YES;Userintraction......

You mean partially bold in a single UILabel. right?
You should check this ONE

Check out with below urls:
Custom Label 1
Custom Label 2
It will be helpful to you and your functionality can be achieved.
Cheers!

Related

single line appears as vertical-center aligned

I have a long text string that I feed into a UILabel for display. The UILabel is dynamically set up to provide sufficient space for the text
specialities1 =[[UILabel alloc]init];
[specialities1 setFrame:CGRectMake(124,218,size8.width, size8.height)];
specialities1.backgroundColor=[UIColor clearColor];**strong text**
specialities1.lineBreakMode=UILineBreakModeClip;
specialities1.font=[UIFont fontWithName:#"Helvetica-Bold" size:14];
specialities1.text=[NSString stringWithFormat:#"%# ",temp ];
specialities1.textAlignment=UITextAlignmentRight;
[specialities1 setNumberOfLines:0];
[specialities1 sizeToFit];
[testscroll addSubview:specialities1];
My problem is if text contains only single line then it appears as vertical-center aligned. That alignment is not matching with my respective label in front of it.
Use below code:
specialities1.lineBreakMode = UILineBreakModeWordWrap;
specialities1.textAlignment = UITextAlignmentLeft;
specialities1.textAlignment = UITextAlignmentLeft; // UITextAlignmentCenter
Choose what you need, depending on the situation you encounter.

iPhone/Objective - C - How to display the whole text of a long string in a UILabel

I have a very long string which is something like that below...
[[sqrt(221)-10,-sqrt(221)-10],[11,11]],[[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*3,rootof([[-3439170900,-50638826700,864180632700,9670592794500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[1477010700,22974524100,-369910322100,-4442729593500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*3],[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*2+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*4,rootof([[-3439170900,-50638826700,864180632700,9670592794500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*2+rootof([[1477010700,22974524100,-369910322100,-4442729593500],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)*4]],[sqrt(sqrt(221)+15),sqrt(-sqrt(221)+15)]
How can i display the whole thing in a UILabel with more than one lines (0)?
Also, although there are no linebreaks ("\n") in the string, the result is displayed like below....
[[sqrt(221)-10,-sqrt(221)- 10],[11,11]],[[rootof([[474368400,2 37184200,- 125944810200,258530778000],[1, 0,- 472,884,42215]])/(sqrt(221)*78270
Any help?
PS I could upload an image but i am not allowed beacause i am a new user...
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
set the UILabel as a multiline
MyLbl.numberOfLines = xxx;
if you have not enough space for set the UIlabel then also set the textView As an not editable property:
Mytxt = [[UITextView alloc]initWithFrame:CGRectMake(xx.0, x.0, xx.0,xx.0)];
Mytxt.transform = transform;
Mytxt.adjustsFontSizeToFitWidth = YES;
Mytxt.textColor = [UIColor blackColor];
Mytxt.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[Mytxt setFont:[UIFont fontWithName:#"Arial" size:xx.0]];
Mytxt.backgroundColor = [UIColor clearColor];
Mytxt.delegate = self;
Mytxt.userInteractionEnabled=YES;
Mytxt.editable=NO;
i hope you get the answer.
You can use UITextView with auto size with non editable mode instead of UILabel (or)
CGSize labelSize = yourString sizeWithFont:cellFont
constrainedToSize:CGSizeMake(190.0f, MAXFLOAT); lineBreakMode:UILineBreakModeWordWrap];
This labelsize will dynamically define the label height you can assign to your label
try this code
NSString *yourString = #"[[sqrt(221)-10,-sqrt(221)-10],[11,11]],[[rootof([[474368400,237184200,-125944810200,258530778000],[1,0,-472,884,42215]])/(sqrt(221)*782707860000)+rootof([[409681800,9099248400,-99876110400,-1875803589000],[1,0,-472,884,42215]])";
UILabel *lblNameDesc=[[UILabel alloc] initWithFrame:CGRectMake(55, 10, 250, 21)];
[lblNameDesc setNumberOfLines:0];
lblNameDesc.text=yourString;
[lblNameDesc setBackgroundColor:[UIColor clearColor]];
[lblNameDesc setTextColor:[UIColor colorWithRed:64.0/255.0 green:64.0/255.0 blue:64.0/255.0 alpha:1.0f]];
[self.view addSubview:lblNameDesc];
// [lblNameDesc release];
[lblNameDesc sizeToFit];
supoose your string is. make your fond and width what ever you want:-
NSString longString = #"dsjkghsdkjnfgvsdjgsl,v.........................";
CGSize maximumLabelSize = CGSizeMake(200,MAXFLOAT);
CGSize expectedLabelSize = [longString sizeWithFont:[UIFont fontWithName:#"Aial-BoldMT" size:15.0] constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, expectedLabelSize.height)];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 0;
myLabel.text = longString ;
may this will help you
Try This...
textLabel.lineBreakMode = YES;
textLabel.numberOfLines = 10; // or many that you need...
You want UILineBreakModeCharacterWrap if you want your text to be evenly distributed along several lines (so it doesn't try to break at work boundaries).

Text is not getting placed as mentioned in CGRect frame of UILable

this might look simple but i am not able to Find the solution for this...when i use this below code the text get placed at right postion as mentioned in the CGRect frame.
[self.view addSubview:[self createLabel:CGRectMake(50,480,50,20):#"Status:"]];
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:#"Arial" size:13];
myLabel.textAlignment = UITextAlignmentLeft;
}
But when i use this below Code the text is getting placed at rightmost corner of the frame...its not getting placed at right position as mentioned in the CGRect frame..can anyone tell whats the problem happening with this..
[self.view addSubview:[self createLabel:CGRectMake(50,340,150,20):aRequests.request_details]];
NOTE:aRequests.request_details is coming from webservices..
Your method doesn't return any object. Try to add return myLabel; at the end of it.
And you are not setting new title: myLabel.text = labelTitle;

How to insert more than one line of data in a single cell of UITableView?

Can I know how can we insert more than one line of data into a single cell of a UITableView,
Just Like, I want the output in a single cell to be like :
KPK
Developer
Infosystems
INDIA
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 80)];
myLabel.text = #"KPK";
myLabel.textAlignment = UITextAlignmentCenter;
myLabel.textColor = [UIColor yellowColor];
[cell addSubview:myLabel];
UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 201, 200, 80)];
myLabel1.text = #"Developer";
myLabel1.textAlignment = UITextAlignmentCenter;
myLabel1.textColor = [UIColor yellowColor];
[cell addSubview:myLabel1];
Use \n as you are using in your string.
Set numberOfLines to 4 to allow for any number of lines.
label.numberOfLines = 4;
Update the label frame to match the size of the text using sizeWithFont:. If you don't do this your text will be vertically centered or cut off.
UILabel *label; // set frame to largest size you want
...
CGSize labelSize = [label.text sizeWithFont:label.font
constrainedToSize:label.frame.size
lineBreakMode:label.lineBreakMode];
label.frame = CGRectMake(
label.origin.x, label.orgin.y,
label.size.width, labelSize.height);
label.text=[NSString stringWithFormat:#"KPK\nDeveloper\nInfosystems\nIndia"];
Now you just need to add the label in your cell.
[cell addSubView:label];
you can place \n in text.Not sure if that works else you can make custom cell for multiple line records.
set tablerow height and Use label in your tableview
Create a custom cell, add 4 labels in it, to display all of your required info. Checkout the following tutorial to see how you can make custom cell.
http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/
Use a uilabel and add that one as the subview if your tableview cell.you can specify the number of lines of uilabel
label.numberOfLines = 4;
I think that the best way is creating a custom UITableViewCell implementation, or programmatically adding UILabels to the cell's contentView.
I.e.:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 200, 30)];
label.text = #"MyText";
label.textColor = [UIColor blackColor];
[cell.contentView addSubview:label];
[label release]; // Never forget this!
When adding the additional rows you should update the first line definition to correctly offset the new rows. Eg. the second label should have something like this:
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(5, 35, 200, 30)];
When you are done, you should implement the tableView:heightForRowAtIndexPath: method in the table's delegate, because you have to define the correct height for the new cell. In your example, for 4 labels you should implement something like this:
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath)indexPath {
if (is_one_of_my_modified_cells) {
return 35*4 + 5;
}
return 44; // default height
}
Try it and let me know.

Another custom UISwitch question

I have looked all over stack overflow, for the answer to this question, and i can only find ways which worked on 4.1 and below, but for 4.2.1 and above, i can't find a new way of getting the text of ON and OFF to change. Is there a way of changing it to say Yes and No.
This is what I have currently:
UISwitch *switchControl = [[UISwitch alloc] initWithFrame:frame];
[switchControl addTarget:self action:action forControlEvents:UIControlEventValueChanged];
switchControl.backgroundColor = [UIColor clearColor];
switchControl.on = value;
[cell addSubview:switchControl];
[switchControl release];
What would be the easiest way of changing the text of the UISwitch? Or would it be easier if i was to make two images and using animation to make them flow, like it is a normal UISwitch.
I wrote up a custom switch class. Hope this helps. http://cl.ly/4OQN
EDIT:
Also, maybe try this:
switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
[switchView setCenter:CGPointMake(160.0f,260.0f)];
[switchView setLeftLabelText: #"Foo"];
[switchView setRightLabelText: #"Bar"];
[[switchView rightLabel] setFont:[UIFont fontWithName:#"Georgia" size:16.0f]];
[[switchView leftLabel] setFont:[UIFont fontWithName:#"Georgia" size:16.0f]];
[[switchView leftLabel] setTextColor:[UIColor yellowColor]];