iTextSharp - Bug in the table functions? - itext

I try to make a table like this:
PdfPTable Table = new PdfPTable(6);
PdfPCell Cell = new PdfPCell(new Phrase("a", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("b", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("c", Font1));
Cell.Colspan = 2;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("d", Font1));
Cell.Colspan = 2;
Table.AddCell(Cell);
That works fine. But changing the number of columns will destory the table. Is it a bug or do I make something wrong?
This code destroys the table:
PdfPTable Table = new PdfPTable(17);
PdfPCell Cell = new PdfPCell(new Phrase("a", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 2;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("b", Font1));
Cell.Rowspan = 2;
Cell.Colspan = 10;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("c", Font1));
Cell.Colspan = 5;
Table.AddCell(Cell);
Cell = new PdfPCell(new Phrase("d", Font1));
Cell.Colspan = 5;
Table.AddCell(Cell);
Edit: The table should have this layout:
|-------------------------------------------------------|
| Cell "a" with | Cell "b" with | Cell "c", colspan = 5 |
| colspan = 2 | colspan = 10 |-----------------------|
| rowspan = 2 | rowspan = 2 | Cell "d", colspan = 5 |
|-------------------------------------------------------|

Add Table.CompleteRow(); as last line.

Related

Append "..." at the end of fourth line

I am displaying text using UILabel. I want to display only 4 lines of text, if there is more text i have to append "..." at the end of fourth line. Any help on this is greatly appreciated. Thanks in advance.
label.numberOfLines = 4;
label.lineBreakMode = NSLineBreakByTruncatingTail;
or in case you support iOS <= 5.
label.lineBreakMode = UILineBreakModeTailTruncation;
lbl.lineBreakMode = UILineBreakModeTailTruncation;
lbl.numberOfLines = 4;
For iOS >= 6,
lbl.lineBreakMode = NSLineBreakByTruncatingTail;
lbl.numberOfLines = 4;

obj c "for loop" road block

Im showing some data in a simple bar that charts some values, all is working, but now to build the scale for my Y axis, im having some problems with some basic stuff,
I get the ceiling value for my chart with scaleMaxInt in this case for testing = 900
then according to some simple test, I get for example 9 divisions [plus zero]...
so to make the thing work, I create the int pp=100
- (void) drawScaleLabels:(int)scaleMaxInt
{
//temp division for scale, NOTE WHERE TO USE 9 DIVISIONS!!
int scaleStep = scaleMaxInt/9;
NSLog(#"va ::%d", scaleStep);
// case scaleMax : 0 < scaleMax < 1000
float scaleDiv = 31.5;
for (int i = 0; i<9; i++)
{ // is 8, to 9 only for testing!!
int pp = 100;
self.divScaleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(469, scaleDiv+286, 60, 14)]autorelease];
self.divScaleLabel.font = [UIFont fontWithName:#"FS Albert" size:14];
self.divScaleLabel.textColor = [UIColor whiteColor];
self.divScaleLabel.textAlignment = UITextAlignmentRight;
self.divScaleLabel.text =[NSString stringWithFormat:#"$%d",scaleMaxInt-scaleStep];
self.divScaleLabel.backgroundColor =[UIColor clearColor];
[self.view addSubview:self.divScaleLabel];
scaleDiv = scaleDiv + 31.5;
scaleStep = scaleStep+pp;
}
}
wich shows the list of values in my Y axis: 900 , 800 , 700 ,600... 0
but if I use the result of the int scaleStep = scaleMaxInt/9
it gives me the list but with the value*2
- (void) drawScaleLabels:(int)scaleMaxInt
{
//temp division for scale, NOTE WHERE TO USE 9 DIVISIONS!!
int scaleStep = scaleMaxInt/9;
NSLog(#"va ::%d", scaleStep);
// case scaleMax : 0 < scaleMax < 1000
float scaleDiv = 31.5;
for (int i = 0; i<9; i++)
{ // is 8, to 9 only for testing!!
//int pp = 100;
self.divScaleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(469, scaleDiv+286, 60, 14)]autorelease];
self.divScaleLabel.font = [UIFont fontWithName:#"FS Albert" size:14];
self.divScaleLabel.textColor = [UIColor whiteColor];
self.divScaleLabel.textAlignment = UITextAlignmentRight;
self.divScaleLabel.text =[NSString stringWithFormat:#"$%d",scaleMaxInt-scaleStep];
self.divScaleLabel.backgroundColor =[UIColor clearColor];
[self.view addSubview:self.divScaleLabel];
scaleDiv = scaleDiv + 31.5;
NSLog(#"va ::%d", scaleStep);
scaleStep = scaleStep+scaleStep;
}
}
so Y axis is, 900, 800 , 700, 500 , 100, -700 ...-24700
Im stupidly stuck with this!,
how can i generate the list for Y axis?, with a dynamic value, dependent of scaleMaxInt
that doesn't get confused??
thanks a lot!
You have this in your loop:
scaleStep = scaleStep+scaleStep;
That means you are doubling scaleStep on each pass through the loop. Remove that line. Instead, set self.divScaleLabel.text like this:
self.divScaleLabel.text =[NSString stringWithFormat:#"$%d", scaleMaxInt - scaleStep * i];

How can I center image in custom cell

In my custom cell I want to center an image but this does not work.
self.leftImage = [[[UIImageView alloc] initWithImage:cry] autorelease] ;
float h=cell.frame.size.height;
float w=cell.frame.size.width;
CGRect r = leftImage.frame;
r.origin = cell.frame.origin;
r.origin.x = w/ 2 - r.size.width / 2;
r.origin.y = h / 2 - r.size.height / 2 + 12;
leftImage.frame = r;
[self.contentView addSubview:leftImage];
I think You tried to do this in - (UITableViewCell *)tableView:(UITableView *)tableViewRef cellForRowAtIndexPath:(NSIndexPath *)indexPath when creating new cell or in cell itself in init section. At this moments cell don't have correct frame and you can't rely on it.
Try setting the leftImage's autoresizingMask:
self.leftImage.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin
When the cell is created, you're never sure what its dimensions are. Mostly, a cell will be initialized with a CGRectZero frame and later on, the UITableView will resize the cell appropriately.

move between uitextview

After several attempts, I decided to write because I just can not figure out how to make it work. I refer to the crossword puzzle.
what I did is this:
- (void) viewDidLoad{
int move = 15;
int h = 50;
for (int i = 0; i < 416; i++){
move = move + 36;
fieldUno = [[UITextField alloc] init];
fieldUno.tag = i;
[fieldUno viewWithTag:i].frame = CGRectMake(move, h, 35, 35);
[fieldUno setBackgroundColor:[UIColor purpleColor]];
[fieldUno setTextAlignment:UITextAlignmentCenter];
[fieldUno setFont:[UIFont fontWithName:#"Times New Roman" size:30]];
[fieldUno setDelegate:self];
[self.view addSubview:[fieldUno viewWithTag:i]];
[fieldUno release];
if (i == 25) h = h + 36, move = 15;
if (i == 51) h = h + 36, move = 15;
if (i == 77) h = h + 36, move = 15;
if (i == 103) h = h + 36, move = 15;
if (i == 129) h = h + 36, move = 15;
if (i == 155) h = h + 36, move = 15;
if (i == 181) h = h + 36, move = 15;
if (i == 207) h = h + 36, move = 15;
if (i == 233) h = h + 36, move = 15;
if (i == 259) h = h + 36, move = 15;
if (i == 285) h = h + 36, move = 15;
if (i == 311) h = h + 36, move = 15;
if (i == 337) h = h + 36, move = 15;
if (i == 363) h = h + 36, move = 15;
if (i == 389) h = h + 36, move = 15;
but now I do not know how to make the next one in reading, with becomeFirstResponder. I wanted to do something quite simple and you can select only the first text box. then do a check on two different arrays to see if the result is wrong or not, but this is already much easier.
what methods should I call? think for example if the tag 1 to tag 5 will be a word, and tag another 7 to 12, I will have to do different if, for each field? and if I were to write vertically? I do not know if I'm on the right track, I was advised to use draw rect but I would follow this way
I apologize if the code is a little messed up.
I did not know how else to do
I'm not completely certain what you're asking, but I'll take a stab at answering anyway. You can add [nextTextField becomeFirstResponder]; to the delegate method textFieldDidEndEditing that takes the user to whichever textField you think he should be at next.

creating thumbnail of an image programmatically

in my application i am getting images from the server and i am able to display the images in image view....
but now i want to store the images getting from the server in a table view and display them while clicking in the table view cell . what i want is how to make the thumbnail of the image in order to display it in table view cell .if i display the image directly in table view cell it is some what appearing clumsy.... for that i want to make the thumbnail of that image and to display it in table view cell...
can any one please help me how to create thumbnail of a image programatically......
Find the blog tutorial for creating thumbnail of an image programmatically
http://johnnytrops.com/blog/wp/2009/02/03/iphone-creating-an-image-thumbnail/
Here is one more
http://www.nickkuh.com/iphone/how-to-create-square-thumbnails-using-iphone-sdk-cg-quartz-2d/2010/03/
- (void) createThumbView { float y_axis = Set y axis;
int x = 0;
int totalImgs = total images;
int tempCnt = 0;
for (int i = 0; i < totalImgs;)
{
float x_axis = set x axis;
int loopCount = 0;
if (totalImgs - tempCnt >= (no of images in row))
{
loopCount = (no of images in row);
}
else
{
loopCount = totalImgs % (no of images in row);
}
for (int j = 0; j < loopCount; j++)
{
MasksData *mData = [masksList objectAtIndex:x];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(x_axis, y_axis, width, height);
[btn setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#.png",mData.bgImage]] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor clearColor];
btn.tag = x;
[scroll View addSubview:btn];
//photoCount++;
x_axis += width + some space;
tempCnt++;
i++;
x++;
}
y_axis += height + some space;
scroll View.contentSize = CGSizeMake(320.0, y_axis);
}