Guest User

Untitled

a guest
Aug 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. - (void)initPageNumbersForPages:(int)count {
  2. pageSpinners = [[NSMutableArray alloc] initWithCapacity:count];
  3.  
  4. for (int i = 0; i < count; i++) {
  5. // ****** Spinners
  6. UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  7. spinner.backgroundColor = [UIColor clearColor];
  8.  
  9. CGRect frame = spinner.frame;
  10. frame.origin.x = pageWidth * i + (pageWidth + frame.size.width) / 2 - 20;
  11. frame.origin.y = (pageHeight + frame.size.height) / 2;
  12. spinner.frame = frame;
  13.  
  14. [pageSpinners addObject:spinner];
  15. [[self scrollView] addSubview:spinner];
  16. [spinner release];
  17.  
  18. // ****** Numbers
  19. NSUInteger width = pageWidth * 0.6;
  20. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(pageWidth * i + (pageWidth) / 2 - (width/2), pageHeight / 2 + 20, width, 100)];
  21. label.backgroundColor = [UIColor clearColor];
  22. label.textColor = [UIColor PAGE_NUMBERS_COLOR];
  23. label.alpha = PAGE_NUMBERS_ALPHA;
  24. label.numberOfLines = 0;
  25. label.lineBreakMode = UILineBreakModeWordWrap;
  26.  
  27. // NSString *labelText = [[NSString alloc] initWithFormat:@"%d", i + 1];
  28.  
  29. // Read title tag --------
  30. // REGEXP for matching title
  31. NSRegularExpression *titleMatcher = [NSRegularExpression regularExpressionWithPattern:@"<title>(.*)</title>"
  32. options:NSRegularExpressionCaseInsensitive
  33. error:NULL];
  34. // read the file content
  35. NSString *fileContents = [NSString stringWithContentsOfFile:[self.pages objectAtIndex: i] encoding:NSUTF8StringEncoding error:NULL];
  36.  
  37. // parse file
  38. //NSArray *matches = [titleMatcher matchesInString:fileContents options:0 range:NSMakeRange(0, [fileContents length])];
  39. //NSString *numberOfMatches = [[NSNumber numberWithInteger:[matches count]] stringValue];
  40.  
  41. //NSRange match = [[matches objectAtIndex:1] range];
  42. NSTextCheckingResult *matchResult = [titleMatcher firstMatchInString:fileContents options:0 range:NSMakeRange(0, [fileContents length])];
  43. NSRange match = [matchResult rangeAtIndex:1];
  44.  
  45.  
  46. //NSString *labelText = [@"Lade Inhalt…" stringByAppendingString:numberOfMatches];
  47. NSString *labelText = @"Loading…";
  48. if (! NSEqualRanges(match, NSMakeRange(NSNotFound, 0))) {
  49. labelText = [@"Loading…\n" stringByAppendingString:[fileContents substringWithRange:match]];
  50. }
  51. // Read title tag end --------
  52.  
  53. // AS: Here goes image creation
  54. UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"28.jpg"]];
  55. [[self scrollView] addSubview:tempImageView];
  56. [tempImageView release];
  57. // AS: End image creation
  58.  
  59. label.font = [UIFont fontWithName:@"Times New Roman" size:18.0];
  60. label.textAlignment = UITextAlignmentCenter;
  61. label.text = labelText;
  62. //label.backgroundColor = [UIColor redColor];
  63. //[labelText release];
  64.  
  65. [[self scrollView] addSubview:label];
  66. [label release];
  67. }
  68. }
Add Comment
Please, Sign In to add comment