0

I am currently building a UIActivityController to share a post to Message, Mail, Twitter and Facebook I currently have this code

NSString *textToShare = string3;
UIImage *imageToShare = [UIImage imageNamed:@"INFO.png"];
NSArray *itemsToShare = @[textToShare, imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:YES completion:nil];

Which is perfect apart from the fact that Twitter Only allows for a certain amount of characters. I have a way of cropping my post so that it fits twitter:

    NSString *shorturl = @"http://vimeo.com/";
    NSString* title = @"LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum LOREM IPSUM lorem ipsum";
    NSString *part1 = [title stringByAppendingString: @" "];

    NSString *hashtag = [@"#" stringByAppendingString: _genret];

    NSString *lengthcheck = [part1 stringByAppendingString: hashtag];
    NSUInteger lenthtotes = [lengthcheck length];
    NSUInteger req = 77;

    NSUInteger lenthhash = 72 -[hashtag length];
    if(lenthtotes > req){
        NSString* tites = [title substringWithRange:NSMakeRange(0, lenthhash)];
        title = [tites stringByAppendingString: @"..."];
        part1 = [title stringByAppendingString: @" "];
    }


    NSString* part2 = [part1 stringByAppendingString: hashtag];


    NSString *part3 = [part2 stringByAppendingString: @" "];

    NSString *string3 = [part3 stringByAppendingString: shorturl];

    NSLog(string3);

Which crops the title to have three "..." if it is longer than the given lengths.

But I want to be able to use the uncropped post for the other three. Is this possible?

maxisme
  • 3,974
  • 9
  • 47
  • 97

0 Answers0