表情代码

   / / = = = = = = = = = = = = = = = = = = 表情键盘弹出 = = = = = = = = = = = = = = = = = = = = = =
/ /    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. view addSubview : 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 ( @ "在此处调用推送接口" ) ;
     return returnView;
}
 
- ( UIView  * ) bubbleView : ( NSString  * ) text
{
 
     UIView  * returnView  =  [self assembleMessageAtIndex : text ];
     return returnView;
}
 
 
< / arrayface.count; >
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值