表情代码

来源:互联网 发布:易语言打开网页源码 编辑:程序博客网 时间:2024/04/28 03:15
  //==================表情键盘弹出======================
//   UIScrollView *faceView =[[UIScrollView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height,kScreenWidth,140)];
     
 
    faceView =[[UIView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height,kScreenWidth,140)];
    faceView.backgroundColor =[UIColor whiteColor];
    [self.viewaddSubview:faceView];
     
     
    for(int i =0; i<40; i++)
    {
        NSString *faceStr;
        if(<10)
        {
            faceStr =[NSString stringWithFormat:@"[smiley_00%d]",i];
        }else
        {
             faceStr =[NSString stringWithFormat:@"[smiley_0%d]",i];
        }
        [arrayFace addObject:faceStr];
    }
     
//   arrayFace =[[NSMutableArray alloc] initWithObjects:@"[/smiley_0]",@"[/smiley_1]",@"[/smiley_2]",@"[/smiley_3]",@"[/smiley_004]",@"[/smiley_005]",@"[/smiley_006]",@"[/smiley_007]",@"[/smiley_008]",@"[/smiley_009]",@"[/smiley_010]",@"[/smiley_011]",@"[/smiley_012]",@"[/smiley_013]",@"[/smiley_014]",@"[/smiley_015]",@"[/smiley_016]",@"[/smiley_017]",@"[/smiley_018]",@"[/smiley_019]",@"[/smiley_020]",@"[/smiley_021]",@"[/smiley_022]",@"[/smiley_023]",@"[/smiley_024]",@"[/smiley_025]",@"[/smiley_026]",@"[/smiley_027]",@"[/smiley_028]",nil];
     
    for(int i =0; i<arrayFace.count; i++)
    {
        NSString *imageStr;
        if(<10)
        {
            imageStr = [NSString stringWithFormat:@"smiley_00%d",i];
        }else
        {
            imageStr =[NSString stringWithFormat:@"smiley_0%d",i];
        }
         
//       NSString*imageStr =[NSString stringWithFormat:@"smiley_%d",i];
        UIButton*faceButt =[UIButton buttonWithType:UIButtonTypeCustom];
        [faceButt setFrame:CGRectMake(10+i%10*30,i/10*30,20,20)];
        [faceButt setBackgroundImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
        [faceButt addTarget:self action:@selector(faceSelect:)forControlEvents:UIControlEventTouchUpInside];
        faceButt.titleLabel.text= [arrayFace objectAtIndex:i];
        [faceView addSubview:faceButt];
    }
 
 
 
#pragma mark - 选中表情获取选中表情信息
-(void)faceSelect:(UIButton*)sender
{
    DLog(@"%@",sender.titleLabel.text);
    faceShow =NO;
    c%@%@",contentStr,[NSString stringWithFormat:@"%@",sender.titleLabel.text]];
    inputText.text = contentStr;
    hiddenTF.hidden = YES;
//    testView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, kScreenWidth - 2 * 10, 40)];
//    testView = [self bubbleView:contentStr];
//    [_baseScrollView addSubview:testView];
    faceView.hidden = YES;
}
//图文混排
-(void)getImageRange:(NSString*)message : (NSMutableArray*)array {
    NSRange range=[message rangeOfString: BEGIN_FLAG];
    NSRange range1=[message rangeOfString: END_FLAG];
    //判断当前字符串是否还有表情的标志。
    if (range.length>0 && range1.length>0)
    {
        if (range.location > 0)
        {
            [array addObject:[message substringToIndex:range.location]];
            [array addObject:[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)]];
            NSString *str=[message substringFromIndex:range1.location+1];
            //            NSString* str = [message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)];
            [self getImageRange:str :array];
        }
        else
        {
            NSString *nextstr=[message substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)];
            //排除文字是“”的
            if (![nextstr isEqualToString:@""])
            {
                [array addObject:nextstr];
                NSString *str=[message substringFromIndex:range1.location+1];
                [self getImageRange:str :array];
            }
            else
            {
                return;
            }
        }
         
    } else if (message.length > 0)
    {
        [array addObject:message];
    }
}
 
 
#pragma mark - 图文混排区域
#define KFacialSizeWidth  20
#define KFacialSizeHeight 20
//#define MAX_WIDTH 150
#define MAX_WIDTH kScreenWidth-2*10
-(UIView *)assembleMessageAtIndex : (NSString *) message
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [self getImageRange:message :array];
    UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero];
    NSArray *data = array;
    UIFont *fon = [UIFont systemFontOfSize:13.0f];
    CGFloat upX = 0;
    CGFloat upY = 0;
    CGFloat X = 0;
    CGFloat Y = 0;
    if (data) {
        for (int i=0;i < [data count];i++) {
            NSString *str=[data objectAtIndex:i];
            NSLog(@"add---str>%@",str);
            if([str hasPrefix:BEGIN_FLAG] &&[str hasSuffix:END_FLAG])
            {
                if(upX >=MAX_WIDTH)
                {
                    upY =upY +KFacialSizeHeight;
                    upX =0;
                    =MAX_WIDTH;
                    =upY;
                }
                NSLog(@"add----str(image)---->%@",str);
                NSString *imageName=[str substringWithRange:NSMakeRange(2,str.length -3)];
 
                 
                NSMutableArray *arrayTemp =[[NSMutableArray alloc] init];
                for(int i =0; i<arrayface.count; i++)="" {="" nsstring="" *strfaceimage;="" strfaceimage="[NSString" stringwithformat:@"smiley_%d",i];="" [arraytemp="" addobject:strfaceimage];="" }="" bool="" isexit="NO;" for="" (int="" z="0;" z<arraytemp.count;="" z++)="" nsstring*="" strtemp="[arrayTemp" objectatindex:z];="" if="" ([strtemp="" isequaltostring:imagename])="" break;="" (!isexit)="" j="0;" <="" [str="" length];="" j++)="" *temp="[str" substringwithrange:nsmakerange(j,="" 1)];="" (upx="">= MAX_WIDTH)
                        {
                            upY = upY + KFacialSizeHeight;
                            upX = 0;
                            X = MAX_WIDTH;
                            Y =upY;
                        }
                        CGSize size=[temp sizeWithFont:fon constrainedToSize:CGSizeMake(150, 40)];
                        UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(upX,upY,size.width,size.height)];
                        la.f>= MAX_WIDTH)
                    {
                        upY = upY + KFacialSizeHeight;
                        upX = 0;
                        X = MAX_WIDTH;
                        Y =upY;
                    }
                    CGSize size=[temp sizeWithFont:fon constrainedToSize:CGSizeMake(150, 40)];
                    UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(upX,upY,size.width,size.height)];
                    la.f%.1f %.1f",X,Y);
     
    DLog(@"在此处调用推送接口");
    returnreturnView;
}
 
-(UIView *)bubbleView:(NSString *)text
{
 
    UIView *returnView = [self assembleMessageAtIndex:text];
    returnreturnView;
}
 
 
</arrayface.count;>
0 0
原创粉丝点击