diff --git a/CustomKeyboard/View/KBKeyboardView.m b/CustomKeyboard/View/KBKeyboardView.m index 3dd7793..3fd6cd2 100644 --- a/CustomKeyboard/View/KBKeyboardView.m +++ b/CustomKeyboard/View/KBKeyboardView.m @@ -279,6 +279,10 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5; title:@"123" output:@"" type:KBKeyTypeModeChange]; + KBKey *customAI = [KBKey keyWithIdentifier:@"ai" + title:@"AI" + output:@"" + type:KBKeyTypeCustom]; KBKey *emoji = [KBKey keyWithIdentifier:KBKeyIdentifierEmojiPanel title:@"😊" output:@"" @@ -291,7 +295,7 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5; title:KBLocalized(@"Send") output:@"\n" type:KBKeyTypeReturn]; - return @[ mode123, emoji, space, ret ]; + return @[ mode123, customAI, emoji, space, ret ]; } // 底部控制行(数字布局) @@ -300,6 +304,10 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5; title:@"abc" output:@"" type:KBKeyTypeModeChange]; + KBKey *customAI = [KBKey keyWithIdentifier:@"ai" + title:@"AI" + output:@"" + type:KBKeyTypeCustom]; KBKey *emoji = [KBKey keyWithIdentifier:KBKeyIdentifierEmojiPanel title:@"😊" output:@"" @@ -312,7 +320,7 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5; title:KBLocalized(@"Send") output:@"\n" type:KBKeyTypeReturn]; - return @[ modeABC, emoji, space, ret ]; + return @[ modeABC, customAI, emoji, space, ret ]; } #pragma mark - Row Building @@ -545,7 +553,7 @@ edgeSpacerMultiplier:(CGFloat)edgeSpacerMultiplier { // - Space:不加宽度约束,依靠左右约束自动填充剩余空间。 - (void)kb_applyBottomControlRowWidthInRow:(UIView *)row { KBKeyButton *modeBtn = nil; - KBKeyButton *aiBtn = nil; + NSMutableArray *customButtons = [NSMutableArray array]; KBKeyButton *spaceBtn = nil; KBKeyButton *retBtn = nil; @@ -558,7 +566,7 @@ edgeSpacerMultiplier:(CGFloat)edgeSpacerMultiplier { modeBtn = b; break; case KBKeyTypeCustom: - aiBtn = b; + [customButtons addObject:b]; break; case KBKeyTypeSpace: spaceBtn = b; @@ -571,19 +579,19 @@ edgeSpacerMultiplier:(CGFloat)edgeSpacerMultiplier { } } - if (!modeBtn || !aiBtn || !spaceBtn || !retBtn) { + if (!modeBtn || customButtons.count == 0 || !spaceBtn || !retBtn) { return; } - // 行高由外部约束为固定值(等于 row1 高度),这里用行高作为“正方形”的边长。 [modeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(row.mas_height).multipliedBy(kKBSpecialKeySquareMultiplier); }]; - [aiBtn mas_makeConstraints:^(MASConstraintMaker *make) { - make.width.equalTo(row.mas_height).multipliedBy(kKBSpecialKeySquareMultiplier); - }]; + for (KBKeyButton *custom in customButtons) { + [custom mas_makeConstraints:^(MASConstraintMaker *make) { + make.width.equalTo(row.mas_height).multipliedBy(kKBSpecialKeySquareMultiplier); + }]; + } [retBtn mas_makeConstraints:^(MASConstraintMaker *make) { - // Send 按钮:宽度为模式键的 2 倍 make.width.equalTo(modeBtn.mas_width).multipliedBy(2.0); }]; // Space 不设置宽度;通过此前已建立的左右约束自动占满剩余宽度。